React-native-reanimated: [Question] Is there any way to loop a animation?

Created on 4 Jan 2019  路  3Comments  路  Source: software-mansion/react-native-reanimated

I cannot find any examples/documentation on how to loop an animation, is this possible? I have tried re-setting the animation value in the completion block off timing().start() and starting a new animation, but the animation will not reanimate.

Bjarte

Most helpful comment

Hi,

I manage to do it like that

function runProgression() {
  const clock = new Clock()

  const state = {
    finished: new Value(0),
    position: new Value(0),
    time: new Value(0),
    frameTime: new Value(0),
  }

  const config = {
    duration: new Value(1000),
    toValue: new Value(1),
    easing: Easing.inOut(Easing.linear),
  }

  return block([
    // start right away
    startClock(clock),

    // process your state
    timing(clock, state, config),

    // when over (processed by timing at the end)
    cond(state.finished, [
      // we stop
      stopClock(clock),

      // set flag ready to be restarted
      set(state.finished, 0),
      // same value as the initial defined in the state creation
      set(state.position, 0),

      // very important to reset this ones !!! as mentioned in the doc about timing is saying
      set(state.time, 0),
      set(state.frameTime, 0),

      // and we restart
      startClock(clock),
    ]),

    state.position,
  ])
}

I'm quite new with reanimated, so there is maybe a better way !
but after tweeting a bit I ended up with this code :)

All 3 comments

Hi,

I manage to do it like that

function runProgression() {
  const clock = new Clock()

  const state = {
    finished: new Value(0),
    position: new Value(0),
    time: new Value(0),
    frameTime: new Value(0),
  }

  const config = {
    duration: new Value(1000),
    toValue: new Value(1),
    easing: Easing.inOut(Easing.linear),
  }

  return block([
    // start right away
    startClock(clock),

    // process your state
    timing(clock, state, config),

    // when over (processed by timing at the end)
    cond(state.finished, [
      // we stop
      stopClock(clock),

      // set flag ready to be restarted
      set(state.finished, 0),
      // same value as the initial defined in the state creation
      set(state.position, 0),

      // very important to reset this ones !!! as mentioned in the doc about timing is saying
      set(state.time, 0),
      set(state.frameTime, 0),

      // and we restart
      startClock(clock),
    ]),

    state.position,
  ])
}

I'm quite new with reanimated, so there is maybe a better way !
but after tweeting a bit I ended up with this code :)

Thanks, that did exactly what I needed :) seems like we don't even need to stop and start the clock

I did tutorial https://www.youtube.com/watch?v=03CGayoqmIk, probably can be helpful.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

WeTruck picture WeTruck  路  3Comments

nextriot picture nextriot  路  3Comments

mrousavy picture mrousavy  路  3Comments

alexfov picture alexfov  路  3Comments

robertgonzales picture robertgonzales  路  3Comments