1

today I want to ask how it would be possible to start an animation from a button onPress event using React Native Reanimated 2? I want to call entering animation like that but it does not work? It looks like i am using useref wrong. My code so far -

  const refAnimated = useAnimatedRef();
 .
 .
 .
<Animated.View
        ref={refAnimated}
        entering={LightSpeedInRight.duration(600)
          .delay(600)
          .springify()
          .damping(15)}
        style={[styles.box, animationStyle]}
      />

   <Button
        title="start"
        onPress={() => {
          refAnimated.current.LightSpeedInRight();
        }}
      />

I have simple Animated.View and a button. When i press the button i want the animation to start again but i get the following error

TypeError: undefined is not an object (evaluating 'refAnimated.value.LightSpeedInRight')

So how can i use ref with reanimated 2?

Benjamin Jones
  • 165
  • 1
  • 7

1 Answers1

0

If you want to keep your animation in the entering prop you could easily let it play by changing the key prop of the component.

miknoup
  • 204
  • 2
  • 5