forked from mrzachnugent/react-native-reusables
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathskeleton.tsx
42 lines (39 loc) · 1.01 KB
/
skeleton.tsx
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
import React from 'react';
import { View } from 'react-native';
import { Button } from '~/components/ui/button';
import { Skeleton } from '~/components/ui/skeleton';
export default function SkeletonScreen() {
const [isLoading, setIsLoading] = React.useState(false);
React.useEffect(() => {
let timeout: ReturnType<typeof setTimeout> | null = null;
if (isLoading) {
timeout = setTimeout(() => {
setIsLoading(false);
}, 3000);
}
return () => {
if (timeout) {
clearTimeout(timeout);
}
};
}, [isLoading]);
return (
<View className='flex-1 justify-center items-center'>
<Skeleton
key={`skeleton-${isLoading}`} // key is not needed if loading only goes one way (not toggled)
show={isLoading}
radius={4}
width={200}
>
<Button
disabled={isLoading}
onPress={() => {
setIsLoading(true);
}}
>
Show Loading
</Button>
</Skeleton>
</View>
);
}