4

I want to use withSequence with a direct value as the first value, using the code bellow caused the app to crash.

animatedValue.value = withSequence(startValue, withTiming(endValue));

The bellow code seems to work perfectly but in my case, it doesn't help using the startValue inside withTiming.

animatedValue.value = withSequence(withTiming(startValue, {duration: 0}), withTiming(endValue));
LHDi
  • 319
  • 1
  • 8
  • by written a chained statement like that, you're sending a state into another hook. But this depends on if the hook takes the value as initial condition or not. Because otherwise the hook might just use it once. To get it working, you need to know what's the input argument for `withSequence`, initial value or a runtime dynamic value. – windmaomao Nov 18 '21 at 16:13
  • 1
    @windmaomao the problem is that I am passing a number to the `withSequance` function and it crashes. but not with animated values. Those aren't states by the way they are shared value, they are used for animation in Reanimated 2. – LHDi Nov 21 '21 at 08:46

1 Answers1

-1

You can just simply set startValue directly to animatedValue.value before triggering the animation:

animatedValue.value = startValue;
animatedValue.value = withTiming(endValue, { duration: 500 })
Dangular
  • 389
  • 1
  • 3
  • 15
  • 2
    it seems that reanimated skips the first assignment for some reason. – LHDi Dec 17 '21 at 08:25
  • Oh ok, I read your question again and realized that I failed to digest your last sentence. Both `withSequence(withTiming(startValue, {duration: 0})...` and my approach works on my side and I'm doubting that there's a part in your code that causes a side effect that prevents `startValue` from getting assigned. Do you mind providing reproducible code? – Dangular Dec 18 '21 at 04:41