|
1 | | -import { Platform, View } from "react-native"; |
2 | | -import { size } from "@expo/ui/jetpack-compose/modifiers"; |
| 1 | +import { useEffect } from "react"; |
| 2 | +import Svg, { Circle } from "react-native-svg"; |
| 3 | +import Animated, { |
| 4 | + Easing, |
| 5 | + useAnimatedProps, |
| 6 | + useSharedValue, |
| 7 | + withDelay, |
| 8 | + withRepeat, |
| 9 | + withTiming, |
| 10 | +} from "react-native-reanimated"; |
3 | 11 | import { useThemeColors } from "utils/theme"; |
4 | 12 | import { testingEnvironment } from "helper/launchArguments"; |
5 | 13 |
|
6 | | -// OS-native indeterminate spinner: Material 3 LoadingIndicator on Android, |
7 | | -// SwiftUI ProgressView on iOS. Static under Detox so the idle-sync doesn't hang. |
| 14 | +const AnimatedCircle = Animated.createAnimatedComponent(Circle); |
| 15 | + |
| 16 | +const SIZE = 64; |
| 17 | +const DURATION = 1800; |
| 18 | +const RADIUS_EASING = Easing.bezier(0.165, 0.84, 0.44, 1); |
| 19 | +const OPACITY_EASING = Easing.bezier(0.3, 0.61, 0.355, 1); |
| 20 | + |
| 21 | +function PuffCircle({ delay, color }: { delay: number; color: string }) { |
| 22 | + const radius = useSharedValue(1); |
| 23 | + const opacity = useSharedValue(1); |
| 24 | + |
| 25 | + useEffect(() => { |
| 26 | + radius.value = withDelay( |
| 27 | + delay, |
| 28 | + withRepeat( |
| 29 | + withTiming(20, { duration: DURATION, easing: RADIUS_EASING }), |
| 30 | + -1, |
| 31 | + ), |
| 32 | + ); |
| 33 | + opacity.value = withDelay( |
| 34 | + delay, |
| 35 | + withRepeat( |
| 36 | + withTiming(0, { duration: DURATION, easing: OPACITY_EASING }), |
| 37 | + -1, |
| 38 | + ), |
| 39 | + ); |
| 40 | + }, [radius, opacity, delay]); |
| 41 | + |
| 42 | + const animatedProps = useAnimatedProps(() => ({ |
| 43 | + r: radius.value, |
| 44 | + strokeOpacity: opacity.value, |
| 45 | + })); |
| 46 | + |
| 47 | + return ( |
| 48 | + <AnimatedCircle |
| 49 | + cx={22} |
| 50 | + cy={22} |
| 51 | + fill="none" |
| 52 | + stroke={color} |
| 53 | + strokeWidth={2} |
| 54 | + animatedProps={animatedProps} |
| 55 | + /> |
| 56 | + ); |
| 57 | +} |
| 58 | + |
| 59 | +// "puff" loader by Sam Herbert (SVG-Loaders, MIT): two expanding, fading |
| 60 | +// rings. Static under Detox so the idle-sync doesn't hang. |
8 | 61 | export default function Spinner() { |
9 | 62 | const colors = useThemeColors(); |
10 | 63 |
|
11 | 64 | if (testingEnvironment()) { |
12 | | - return <View style={{ width: 48, height: 48 }} />; |
13 | | - } |
14 | | - |
15 | | - if (Platform.OS === "android") { |
16 | | - const { Host, LoadingIndicator } = |
17 | | - require("@expo/ui/jetpack-compose") as typeof import("@expo/ui/jetpack-compose"); |
18 | 65 | return ( |
19 | | - <Host matchContents> |
20 | | - <LoadingIndicator |
21 | | - color={colors.primary} |
22 | | - modifiers={[size(48, 48)]} |
| 66 | + <Svg width={SIZE} height={SIZE} viewBox="0 0 44 44"> |
| 67 | + <Circle |
| 68 | + cx={22} |
| 69 | + cy={22} |
| 70 | + r={10} |
| 71 | + fill="none" |
| 72 | + stroke={colors.primary} |
| 73 | + strokeWidth={2} |
| 74 | + strokeOpacity={0.5} |
23 | 75 | /> |
24 | | - </Host> |
| 76 | + </Svg> |
25 | 77 | ); |
26 | 78 | } |
27 | 79 |
|
28 | | - const { Host, ProgressView } = |
29 | | - require("@expo/ui/swift-ui") as typeof import("@expo/ui/swift-ui"); |
30 | 80 | return ( |
31 | | - <Host matchContents> |
32 | | - <ProgressView /> |
33 | | - </Host> |
| 81 | + <Svg width={SIZE} height={SIZE} viewBox="0 0 44 44"> |
| 82 | + <PuffCircle delay={0} color={colors.primary} /> |
| 83 | + <PuffCircle delay={DURATION / 2} color={colors.primary} /> |
| 84 | + </Svg> |
34 | 85 | ); |
35 | 86 | } |
0 commit comments