-
-
Notifications
You must be signed in to change notification settings - Fork 1.4k
fix: withSpring color properties flickering #6821
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
patrycjakalinska
merged 3 commits into
main
from
@patrycjakalinska/withSpring-color-flickering-fix
Jan 29, 2025
Merged
fix: withSpring color properties flickering #6821
patrycjakalinska
merged 3 commits into
main
from
@patrycjakalinska/withSpring-color-flickering-fix
Jan 29, 2025
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
tjzel
reviewed
Dec 17, 2024
piaskowyk
requested changes
Jan 2, 2025
piaskowyk
approved these changes
Jan 29, 2025
tjzel
pushed a commit
that referenced
this pull request
Feb 17, 2025
## Summary This PR addresses an issue where color-based properties (`backgroundColor`, `boxShadow`) were causing flickering when used with withSpring animations. The root cause of the flickering was RGBA values going below `0`, resulting in `NaN` values. I introduced `clampRGBA` function that guards values within given limits. Before: https://github.com/user-attachments/assets/ace128a8-3f4b-41be-98c6-d34339808283 After: https://github.com/user-attachments/assets/b29f1248-2385-48c2-8fad-e261ee21b46a ## Test plan Paste this code to EmptyExample - it should work on both Paper and Fabric: <details> <summary>EmptyExample code</summary> ```js import { Text, StyleSheet, View, Pressable } from 'react-native'; import React from 'react'; import Animated, { useSharedValue, withSpring, useAnimatedStyle, } from 'react-native-reanimated'; export default function EmptyExample() { const pressed = useSharedValue(false); const animatedStyle = useAnimatedStyle(() => { return { backgroundColor: withSpring(pressed.value ? 'blue' : 'red'), }; }); return ( <View> <Animated.View style={[styles.box, animatedStyle]} /> <Pressable onPress={() => { pressed.value = !pressed.value; }}> <Text>Press me</Text> </Pressable> </View> ); } const styles = StyleSheet.create({ box: { width: 50, height: 50, }, }); ``` </details>
tjzel
pushed a commit
that referenced
this pull request
Feb 17, 2025
## Summary This PR addresses an issue where color-based properties (`backgroundColor`, `boxShadow`) were causing flickering when used with withSpring animations. The root cause of the flickering was RGBA values going below `0`, resulting in `NaN` values. I introduced `clampRGBA` function that guards values within given limits. Before: https://github.com/user-attachments/assets/ace128a8-3f4b-41be-98c6-d34339808283 After: https://github.com/user-attachments/assets/b29f1248-2385-48c2-8fad-e261ee21b46a ## Test plan Paste this code to EmptyExample - it should work on both Paper and Fabric: <details> <summary>EmptyExample code</summary> ```js import { Text, StyleSheet, View, Pressable } from 'react-native'; import React from 'react'; import Animated, { useSharedValue, withSpring, useAnimatedStyle, } from 'react-native-reanimated'; export default function EmptyExample() { const pressed = useSharedValue(false); const animatedStyle = useAnimatedStyle(() => { return { backgroundColor: withSpring(pressed.value ? 'blue' : 'red'), }; }); return ( <View> <Animated.View style={[styles.box, animatedStyle]} /> <Pressable onPress={() => { pressed.value = !pressed.value; }}> <Text>Press me</Text> </Pressable> </View> ); } const styles = StyleSheet.create({ box: { width: 50, height: 50, }, }); ``` </details>
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Summary
This PR addresses an issue where color-based properties (
backgroundColor
,boxShadow
) were causing flickering when used with withSpring animations. The root cause of the flickering was RGBA values going below0
, resulting inNaN
values.I introduced
clampRGBA
function that guards values within given limits.Before:
Screen.Recording.2024-12-16.at.11.14.39.mov
After:
Screen.Recording.2024-12-16.at.11.15.03.mov
Test plan
Paste this code to EmptyExample - it should work on both Paper and Fabric:
EmptyExample code