You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
fix: Implement correct transparent color interpolation (#8398)
## Summary
This PR fixes the `interpolateColor` interpolation between
non-transparent colors and `'transparent'` (keyword) color. The previous
implementation was incorrect as it converted `'transparent'` to the
`0x00000000` (black transparent), but the `'transparent'` keyword is not
just a black transparent color. Because of that, the interpolation
from/to the transparent color always changed the color to black (the
difference can be seen on the recordings below).
## Example recordings
If you pause recordings and compare, you can see that the **Before** one
goes through a dirty yellow to transparent because it becomes more and
more black on each animation step.
| Before | After |
|-|-|
| <video
src="https://github.com/user-attachments/assets/860467b1-4ca9-4fad-9952-0886f131443b"
/> | <video
src="https://github.com/user-attachments/assets/a8320a68-924e-44bd-8806-5569b79504b8"
/> |
<details>
<summary>Example source code</summary>
```tsx
import React, { useEffect } from 'react';
import { StyleSheet } from 'react-native';
import Animated, {
interpolateColor,
useAnimatedStyle,
useSharedValue,
withRepeat,
withTiming,
} from 'react-native-reanimated';
export default function EmptyExample() {
const sv = useSharedValue(0);
const animatedStyle = useAnimatedStyle(() => ({
backgroundColor: interpolateColor(
sv.value,
[0, 1],
['yellow', 'transparent']
),
}));
useEffect(() => {
sv.value = 0;
sv.value = withRepeat(withTiming(1, { duration: 3000 }), -1, true);
}, [sv]);
return <Animated.View style={[styles.container, animatedStyle]} />;
}
const styles = StyleSheet.create({
container: {
flex: 1,
},
});
```
</details>
0 commit comments