1

我试图让元素一旦PanGestureHandler被释放就返回到它的初始位置。

onGestureEvent = event(
    [
      {
        nativeEvent: ({ translationY, state, velocityY }) =>
          cond(
            eq(state, State.ACTIVE),
            // ignore this part, it's working fine
            [
              cond(
                lessOrEq(this.scrollOffset, 0),
                set(
                  this.gestureY,
                  divide(sub(translationY, this.ignoredGestureY), 2)
                ),
                set(this.ignoredGestureY, translations)
              )
            ],
            [
              // here I invoke bounce back animation
              set(
                this.gestureY,
                runTiming(this.backClock, this.gestureY, new Value(0))
              )
            ]
          )
      }
    ],
    { useNativeDriver: true }
  )

这是runTiming功能:

function runTiming (clock, value, dest, startStopClock = true) {
  const state = {
    finished: new Value(0),
    position: new Value(0),
    frameTime: new Value(3000),
    time: new Value(3000)
  }

  const config = {
    toValue: new Value(0),
    duration: 3000,
    easing: Easing.ease
  }

  return [
    cond(clockRunning(clock), 0, [
      set(state.finished, 0),
      set(state.frameTime, 3000),
      set(state.time, 3000),
      set(state.position, value),
      set(config.toValue, dest),
      startClock(clock)
    ]),
    timing(clock, state, config),
    cond(state.finished, stopClock(clock)),
    state.position
  ]
}

问题是元素立即返回。为什么 3000 毫秒的持续时间不起作用?

4

0 回答 0