Skip to content
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

fix: withSpring color properties flickering #6821

Open
wants to merge 3 commits into
base: main
Choose a base branch
from

Conversation

patrycjakalinska
Copy link
Contributor

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:

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
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,
  },
});

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants