question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

interpolateColor and withTiming with duration < 250ms dont work in web

See original GitHub issue

Description

When doing a withTiming color animation on web with less than 250 in duration and a scale withSpring animation it reverts to first color on completion

Using interpolateColor function from react-native-reanimated but tested with the one from react-native-redash and same issue

Screenshots

Web example with error anim

working example on emulator workinganim

Steps To Reproduce

Expected behavior

Row should turn green in web

Actual behavior

Row goes back to background color

Snack or minimal code example

here below is the component getting set active on press. Removed other animations for simplicty

export const EmojiButton = ({active, onPress}) => {
  const theme = useTheme();

  const color = useSharedValue(0);
  const scale = useSharedValue(1);

  useEffect(() => {
    if (active) {
      color.value = withTiming(2, {duration: 249, easing: Easing.linear});
      scale.value = withSpring(1.2, {stiffness: 400, damping: 10});
    } else {
      color.value = 0;
      scale.value = 1;
    }
  }, [active]);

  const animationStyles = useAnimatedStyle(() => {
    return {
      backgroundColor: interpolateColor(
        color.value,
        [0, 1, 2],
        [theme.backgroundColor, theme.buttonPressedColor, theme.primaryColor],
      ),
      transform: [
        {
          scaleY: scale.value,
        },
      ],
    };
  }, [theme]);

  return (
    <Pressable onPress={onPress}>
      <Animated.View
        style={[
          {
            height: 80,
            borderBottomColor: theme.dividerColor,
            borderBottomWidth: 1,
          },
          animationStyles,
        ]}
      />
    </Pressable>
  );
};

Package versions

  • React: 6.13.1
  • React Native: 0.63.3
  • React Native Reanimated: react-native-reanimated@2.0.0-alpha.9
  • NodeJS: 14.15.0
  • react-native-web@0.14.7

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Reactions:1
  • Comments:9 (5 by maintainers)

github_iconTop GitHub Comments

2reactions
piaskowykcommented, Mar 29, 2021

My PR for react-native-web with the fix of this issue is on the roadmap to release RNW. I suppose It’ll be merged within the next release of RNW.

2reactions
piaskowykcommented, Nov 27, 2020

The issue is the effect of changes in react-native-web 0.13. The RNW team removed forwardedRef props. 😔
We wait for patch and stay with version 0.12. More information here and here

Read more comments on GitHub >

github_iconTop Results From Across the Web

withTiming | React Native Reanimated
Starts a time based animation. Arguments​. toValue [number | string]​. The target value at which the animation should conclude. It can be specified...
Read more >
How to add animations to your NativeBase App
So, in this tutorial, we will share with you, how to add animations to your NativeBase app, using Reanimated . What are We...
Read more >
Reanimated 2 - the new approach to creating animations in ...
We are going to build practical examples of animated sliders using the new Reanimated 2 API and our custom useSlider hook. You don't...
Read more >
Interpolate Colors like a pro with React Native Reanimated 2 ...
Your browser can't play this video. ... main concepts we'll explore are: - useDerivedValue - interpolateColor - withTiming Medium article: ...
Read more >
Introduction to React Native Reanimated - Prototyped
Your React Native app is not fancy enough? ... Animation helpers like withTiming and withSpring are used to animate the circle.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found