|
1 | 1 | import type { SkSize } from "@shopify/react-native-skia";
|
2 |
| -import { Canvas, Fill, Group, Rect, rect } from "@shopify/react-native-skia"; |
| 2 | +import { |
| 3 | + BlurMask, |
| 4 | + Canvas, |
| 5 | + Circle, |
| 6 | + Fill, |
| 7 | + Group, |
| 8 | + mix, |
| 9 | + polar2Canvas, |
| 10 | + vec, |
| 11 | +} from "@shopify/react-native-skia"; |
3 | 12 | import React, { useEffect, useRef } from "react";
|
4 | 13 | import { View, Animated } from "react-native";
|
5 | 14 | import { useNavigation } from "@react-navigation/native";
|
6 | 15 | import { useContextBridge } from "its-fine";
|
7 | 16 | import type { SharedValue } from "react-native-reanimated";
|
8 | 17 | import { useDerivedValue, useSharedValue } from "react-native-reanimated";
|
9 | 18 |
|
10 |
| -interface MyCompProps { |
| 19 | +import { useLoop } from "../../components/Animations"; |
| 20 | + |
| 21 | +const c1 = "#61bea2"; |
| 22 | +const c2 = "#529ca0"; |
| 23 | + |
| 24 | +interface SizeProps { |
11 | 25 | size: SharedValue<SkSize>;
|
12 | 26 | }
|
13 | 27 |
|
14 |
| -const MyComp = ({ size }: MyCompProps) => { |
| 28 | +interface RingProps extends SizeProps { |
| 29 | + index: number; |
| 30 | + progress: SharedValue<number>; |
| 31 | +} |
| 32 | + |
| 33 | +const Ring = ({ index, progress, size }: RingProps) => { |
| 34 | + const R = useDerivedValue(() => size.value.width / 4); |
| 35 | + const center = useDerivedValue(() => |
| 36 | + vec(size.value.width / 2, size.value.height / 2 - 64) |
| 37 | + ); |
| 38 | + |
| 39 | + const theta = (index * (2 * Math.PI)) / 6; |
| 40 | + const transform = useDerivedValue(() => { |
| 41 | + const { x, y } = polar2Canvas( |
| 42 | + { theta, radius: progress.value * R.value }, |
| 43 | + { x: 0, y: 0 } |
| 44 | + ); |
| 45 | + const scale = mix(progress.value, 0.3, 1); |
| 46 | + return [{ translateX: x }, { translateY: y }, { scale }]; |
| 47 | + }, [progress, R]); |
| 48 | + |
| 49 | + return ( |
| 50 | + <Circle |
| 51 | + c={center} |
| 52 | + r={R} |
| 53 | + color={index % 2 ? c1 : c2} |
| 54 | + origin={center} |
| 55 | + transform={transform} |
| 56 | + /> |
| 57 | + ); |
| 58 | +}; |
| 59 | + |
| 60 | +const BreatheDemo = ({ size }: SizeProps) => { |
| 61 | + const center = useDerivedValue(() => |
| 62 | + vec(size.value.width / 2, size.value.height / 2 - 64) |
| 63 | + ); |
| 64 | + |
| 65 | + const progress = useLoop({ duration: 3000 }); |
| 66 | + |
| 67 | + const transform = useDerivedValue( |
| 68 | + () => [{ rotate: mix(progress.value, -Math.PI, 0) }], |
| 69 | + [progress] |
| 70 | + ); |
| 71 | + |
| 72 | + return ( |
| 73 | + <> |
| 74 | + <Fill color="rgb(36,43,56)" /> |
| 75 | + <Group origin={center} transform={transform} blendMode="screen"> |
| 76 | + <BlurMask style="solid" blur={40} /> |
| 77 | + {new Array(6).fill(0).map((_, index) => { |
| 78 | + return ( |
| 79 | + <Ring size={size} key={index} index={index} progress={progress} /> |
| 80 | + ); |
| 81 | + })} |
| 82 | + </Group> |
| 83 | + </> |
| 84 | + ); |
| 85 | +}; |
| 86 | + |
| 87 | +const MyComp = ({ size }: SizeProps) => { |
15 | 88 | const navigation = useNavigation();
|
16 | 89 | const { routeNames } = navigation.getState()!;
|
17 | 90 | console.log({ routeNames });
|
18 |
| - const rct = useDerivedValue(() => { |
19 |
| - return rect(0, 0, size.value.width, size.value.height / 2); |
20 |
| - }, [size]); |
21 | 91 | return (
|
22 | 92 | <Group>
|
23 |
| - <Fill color="magenta" /> |
24 |
| - <Rect color="cyan" rect={rct} /> |
| 93 | + <BreatheDemo size={size} /> |
25 | 94 | </Group>
|
26 | 95 | );
|
27 | 96 | };
|
|
0 commit comments