Created
November 4, 2023 10:21
-
-
Save wcandillon/da5715b7b107bee808193cb637f8539f to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import { | |
Canvas, | |
Group, | |
Rect, | |
Skia, | |
useClock, | |
} from "@shopify/react-native-skia"; | |
import React from "react"; | |
import { StyleSheet, View } from "react-native"; | |
import Animated, { | |
useAnimatedStyle, | |
useDerivedValue, | |
} from "react-native-reanimated"; | |
const array = new Array(1).fill(0).map((_, index) => index); | |
const paint = Skia.Paint(); | |
paint.setColor(Skia.Color("pink")); | |
export default function App() { | |
const clock = useClock(); | |
const offsetTx = useDerivedValue(() => [ | |
{ translateY: 300 + Math.sin(clock.value / 300) * 300 - 300 }, | |
]); | |
const style = useAnimatedStyle(() => ({ | |
...StyleSheet.absoluteFillObject, | |
transform: [{ translateY: 300 + Math.sin(clock.value / 300) * 300 - 300 }], | |
})); | |
return ( | |
<View | |
style={{ | |
flex: 1, | |
flexDirection: "row", | |
}} | |
> | |
<View style={{ flex: 1 }}> | |
<Animated.View style={style}> | |
{array.map((index) => ( | |
<View | |
key={index} | |
style={{ | |
position: "absolute", | |
top: 150 * index + 50, | |
left: 15, | |
width: 100, | |
height: 100, | |
backgroundColor: "blue", | |
}} | |
/> | |
))} | |
</Animated.View> | |
</View> | |
<Canvas | |
mode="continuous" | |
style={StyleSheet.absoluteFill} | |
pointerEvents="none" | |
> | |
<Group transform={offsetTx}> | |
{array.map((index) => ( | |
<Rect | |
key={index} | |
x={15} | |
y={150 * index + 50} | |
width={100} | |
height={100} | |
color="green" | |
/> | |
))} | |
</Group> | |
</Canvas> | |
</View> | |
); | |
} |
Author
wcandillon
commented
Nov 4, 2023
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment