In React Native, if I have an Animated.Value that I want to animate from 0 to, say, 49.
const animatedValue = new Animated.Value(0)
const animate = () => {
animatedValue.setValue(0)
Animated.timing(animatedValue, {
toValue: 49,
duration: 1000,
}).start()
}
And I have an array with 50 elements (for the example, let's say the names of the 50 US states)
const states = ["Alabama", ..., "Wyoming"]
Is there a way for me to display the value of the "current" index of the array in a component? For example, I want something like this, although this does not work:
<Pressable onPress={animate}>
<Text>{states[Math.floor(animatedValue)]}</Text>
</Pressable>
I want that to cycle through the list of states (settling on Wyoming, as it's last) when I press the Pressable. It feels like there should be a way I can do this, although I can't seem to find one.