software-mansion / react-native-reanimated

React Native's Animated library reimplemented
https://docs.swmansion.com/react-native-reanimated/
MIT License
8.59k stars 1.26k forks source link

Properly stringify tiny color values #6153

Closed swansontec closed 6 days ago

swansontec commented 1 week ago

Summary

If the interpolated alpha value is really tiny, the code might emit a string like "rgba(0, 0, 0, 1e-11)". This is not valid syntax, and can cause worklet crashes. Replace these small values with 0.

Test plan

This PR includes the necessary unit-test update:

  it('handles tiny values', () => {
    const colors = ['#00000000', '#ff802001'];

    // We don't want output like "rgba(4, 2, 0, 3.921568627450981e-7)":
    const interpolatedColor = interpolateColor(0.0001, [0, 1], colors);
    expect(interpolatedColor).toBe(`rgba(4, 2, 0, 0)`);
  });