4

I am struggling with React Native Animations here. The outcome is simple, I have an Animated.Image which I want to spin.
All good, until I want to loop thru the animation for n times and do something when it stops.
I have the following code .

Animated.loop(
  Animated.timing(this.state.spin, {
    toValue: 360,
    duration: 1000,
    easing: Easing.linear,
    useNativeDriver: true,
  }), {
    iterations: 3
  }
).start(() => {
  console.log('done');
});

It spins 3 times as per loop iteration but no callback was fired when animation ends.

Here the Expo which replicates this: https://snack.expo.io/S1PjnfB9-

2 Answers 2

2

Try the code below

Animated.loop(
  Animated.timing(this.state.spin, {
    toValue: 360,
    duration: 1000,
    easing: Easing.linear,
    useNativeDriver: true,
  }), {
    iterations: 3
  }
).start(event => {
    if (event.finished) {
      console.log('finished');
    }
  });

I just added a check on the event response.

Hope it helps.

Sign up to request clarification or add additional context in comments.

1 Comment

Nope... Still does`t work. The callback function is not called on end event.
1

Found the answer.
It seems that if you take out useNativeDriver it works as it should be, and the callback is called.
This is weird...

1 Comment

I am encounting a situation at where after I add one line : userNativeDriver :true, the Callback will be called once.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.