How to detect when an animated element has reached a certain position. The element should not stop in this position. It should continue the off-screen animation.
When an element exceeds the given position (line), I have to trigger some action (e.g. change the color of the line to red).
const Component = () => {
const moveAnimX = useRef(new Animated.Value(0)).current;
const runAnimation = () => {
Animated.timing(moveAnimX, {
toValue: 2000, // out of screen
duration: 1500,
useNativeDriver: true,
}).start();
};
useEffect(() => {
runAnimation();
}, []);
return (
<Animated.View
style={[
{
height: 50,
width: 50,
backgroundColor: 'red',
transform: [
{
translateX: moveAnimX,
},
],
},
]}
/>
);
};