|
1 | 1 | import React from "react"; |
2 | 2 | import { |
3 | 3 | Box, |
| 4 | + Button, |
4 | 5 | CircularProgress, |
5 | 6 | useTheme, |
6 | 7 | } from "@adaptui/react-native-tailwind"; |
7 | 8 |
|
| 9 | +const useCircularProgressState = (initialValue: number | null = 0) => { |
| 10 | + const [value, setValue] = React.useState<number | null>(initialValue); |
| 11 | + |
| 12 | + React.useEffect(() => { |
| 13 | + const clearId = setInterval(() => { |
| 14 | + setValue(prevValue => { |
| 15 | + if (prevValue == null) { |
| 16 | + return prevValue; |
| 17 | + } |
| 18 | + return prevValue + 5; |
| 19 | + }); |
| 20 | + }, 500); |
| 21 | + |
| 22 | + if (value === 100) { |
| 23 | + clearInterval(clearId); |
| 24 | + } |
| 25 | + |
| 26 | + return () => { |
| 27 | + clearInterval(clearId); |
| 28 | + }; |
| 29 | + }, [setValue, value]); |
| 30 | + |
| 31 | + return [value, setValue] as const; |
| 32 | +}; |
| 33 | + |
8 | 34 | export const CircularProgressScreen = () => { |
9 | 35 | const tailwind = useTheme(); |
| 36 | + const [value, setValue] = useCircularProgressState(); |
10 | 37 | return ( |
11 | 38 | <Box |
12 | 39 | style={tailwind.style( |
13 | 40 | "flex-1 justify-center items-center px-2 bg-white-900", |
14 | 41 | )} |
15 | 42 | > |
16 | | - <CircularProgress size="sm" /> |
17 | | - <CircularProgress /> |
18 | | - <CircularProgress size="lg" /> |
19 | | - <CircularProgress size="xl" /> |
| 43 | + <Box style={tailwind.style("my-5")}> |
| 44 | + <CircularProgress size="sm" /> |
| 45 | + </Box> |
| 46 | + <Box style={tailwind.style("my-5")}> |
| 47 | + <CircularProgress themeColor="primary" /> |
| 48 | + </Box> |
| 49 | + <Box style={tailwind.style("my-5")}> |
| 50 | + <CircularProgress |
| 51 | + style={tailwind.style("w-48 h-48")} |
| 52 | + themeColor="primary" |
| 53 | + progressTrackColor={tailwind.getColor("text-green-600")} |
| 54 | + /> |
| 55 | + </Box> |
| 56 | + <Box style={tailwind.style("my-5")}> |
| 57 | + <CircularProgress size="lg" /> |
| 58 | + </Box> |
| 59 | + <Box style={tailwind.style("my-5")}> |
| 60 | + <CircularProgress value={value} themeColor="primary" size="xl" /> |
| 61 | + </Box> |
| 62 | + <Box style={tailwind.style("my-5")}> |
| 63 | + <CircularProgress |
| 64 | + hint={`${value}%`} |
| 65 | + value={value} |
| 66 | + themeColor="primary" |
| 67 | + size="xl" |
| 68 | + /> |
| 69 | + </Box> |
| 70 | + <Box style={tailwind.style("flex-row justify-center w-full")}> |
| 71 | + <Button onPress={() => setValue(0)}>Reset</Button> |
| 72 | + <Button variant="ghost" onPress={() => setValue(null)}> |
| 73 | + Make Indeterminate |
| 74 | + </Button> |
| 75 | + </Box> |
20 | 76 | </Box> |
21 | 77 | ); |
22 | 78 | }; |
0 commit comments