useAnimatedStyle
イメージとしてはこういう風に書きたい
NG(tsx)<Animated.View style={{ width: width += 50 }} />
↑のようにはかけないので、
代わりに、useAnimatedStyleを使って以下のように書く
tsexport default function App() {
const translateX = useSharedValue<number>(0);
const handlePress = () => {
translateX.value += 50;
};
const animatedStyles = useAnimatedStyle(() => ({
transform: [{ translateX: withSpring(translateX.value * 2) }],
}));
return (
<>
<Animated.View style={[styles.box, animatedStyles]} />
<View style={styles.container}>
<Button onPress={handlePress} title="Click me" />
</View>
</>
);