Skip to content
Draft
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 22 additions & 1 deletion App.js
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,18 @@ const Game = () => {
],
}));

// Setup the device motion sensor listener
// Start with the target in a random position
const targetAnimation = useSharedValue(getRandomTargetPosition());

// Create the target styles based on the current ballAnimation value
const targetPosition = useAnimatedStyle(() => ({
transform: [
{ translateX: targetAnimation.value.x },
{ translateY: targetAnimation.value.y },
],
}));

// Setup the device motion sensor listner
React.useEffect(() => {
// Set the update interval to 16ms (60fps)
DeviceMotion.setUpdateInterval(16);
Expand All @@ -79,6 +90,8 @@ const Game = () => {

return (
<View style={styles.container}>
<Reanimated.View style={[styles.target, targetPosition]} />

<Reanimated.View style={[styles.ball, ballPosition]} />
</View>
);
Expand All @@ -96,4 +109,12 @@ const styles = StyleSheet.create({
borderRadius: BALL_WIDTH,
backgroundColor: "red",
},
target: {
position: "absolute",
width: TARGET_WIDTH,
height: TARGET_WIDTH,
borderRadius: TARGET_WIDTH,
borderWidth: TARGET_BORDER_WIDTH,
borderColor: "blue",
},
});