rerendering breaks withRepeat animation
See original GitHub issueDescription
I have withRepeat animation and some useState value.
const [state, setState] = useState(0);
const val = useSharedValue(1);
val.value = withRepeat(withTiming(1.5, { duration: 2000 }), -1, true);
Any state change will fix the val.value range between 1.5 and the value at rerendering moment
Video
Steps To Reproduce
- Create withRepeat animation
- Add some state
- Update state
Expected behavior
val.value will change in [1, 1.5] range
Actual behavior
val.value changes in [value at the rerendering moment, 1.5] range
Snack or minimal code example
function App() {
const [state, setState] = useState(0);
const val = useSharedValue(1);
val.value = withRepeat(withTiming(1.5, { duration: 2000 }), -1, true);
const debug = useDerivedValue(() => {
console.log(val.value);
return val.value;
});
const style = useAnimatedStyle(() => {
return {
transform: [{ scale: val.value }],
};
});
return (
<View style={styles.container}>
<Animated.View style={[styles.element, style]} />
<Button title="useless button" onPress={() => setState(state + 1)} />
</View>
);
}
const styles = StyleSheet.create({
container: {
flex: 1,
justifyContent: "center",
alignItems: "center",
},
element: {
backgroundColor: "red",
width: 100,
height: 100,
marginBottom: 50,
},
});
Package versions
- React: 16.13.1
- React Native: 0.63.4
- React Native Reanimated: 2.0.0-alpha.9.2
- NodeJS: 14.15.1
Issue Analytics
- State:
- Created 3 years ago
- Reactions:1
- Comments:5
Top Results From Across the Web
withRepeat | React Native Reanimated - Software Mansion
Repeats the provided animation several times. ... be called when all repetitions of the provided animation are complete or when withRepeat is cancelled....
Read more >Rerendering componet breaks animations (React Native ...
- When the component rerenders it breaks the gesture-animation setup. It seems to me that, gesture stays the same and gets the events...
Read more >My animation is not working when re rendering my react ...
So, my problem is that I have a component, I associated an animation to it and it is working when the component is...
Read more >react-native-reanimated: Versions - Openbase
Added measure and scrollTo for web #3661; [Fix] Ignore layout animation props ... fix: breaking change in babel by @hosseinmd in ... rerender...
Read more >5 React Native animations made easy - Bam Tech
Whilst animating the opacity, use the combination of three utils: withRepeat: animates infinitely in both directions; withSequence: creates a ...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
can you try this?
Use withRepeat without useEffect works sometimes, but I don’t know why Should I use withRepeat wrap with useEffect every time?