【问题标题】:React Native Reanimated output value from Animated.interpolate来自 Animated.interpolate 的 React Native Reanimated 输出值
【发布时间】:2020-06-19 12:37:25
【问题描述】:

我了解 Animated.Code 我在每一帧中都得到了 console.log

我想知道 Animated.interpolate 的输出当前值

代码片段

 const diffClampScrollY = Animated.diffClamp(this.props.Animation_Header_Heaght, 0, HEADER_HEIGHT)

    const headerY = Animated.interpolate(diffClampScrollY, {
        inputRange: [0, HEADER_HEIGHT],
        outputRange: [0, -HEADER_HEIGHT],
    })
render(){
   return(
    <Animated.Code>
       {() =>
         call([headerY], () => {
         console.log(headerY)
       })
    </Animated.Code>
  )
 }

我不明白来自console.log(headerY)的对象

我想知道单个当前值?

【问题讨论】:

标签: reactjs react-native react-native-reanimated react-native-gesture-handler


【解决方案1】:

call(argsNodes, callback) 根据重新激活的documentation,如果 argsNodes 数组中的一个节点更新,将在 JavaScript 中调用回调,并将 argsNodes 数组中节点的当前值列表作为第一个参数。 要控制headerY 的值,您需要将其作为回调函数的参数传递以访问它,如下所示:

  ...
    <Animated.Code>
       {() =>
         call([headerY], ([headerY]) => {
         console.log(headerY)
       })
    </Animated.Code>

【讨论】:

    【解决方案2】:

    把它放在你的 Animated.Code 块中;

    {() => 调试('headerY: ', headerY)}

    原因是 headerY 是一个节点,因此您不能只记录它。您必须使用特制的日志节点才能记录节点值。

    【讨论】:

    • 当使用调试时,我的应用程序被粉碎并给我这个消息 => 期望 'exec' 道具或孩子是动画节点或返回动画节点的函数。将“对象”类型传递给孩子
    • 我现在无法测试任何东西,但只是想一想,您是否尝试过仅将 console.log() 替换为 debug('headerY: ', headerY)?所以你保持通话和一切
    猜你喜欢
    • 2022-11-17
    • 2020-10-19
    • 2021-08-19
    • 2022-01-11
    • 2022-10-15
    • 2020-10-12
    • 2021-11-27
    • 2021-11-08
    • 2021-11-23
    相关资源
    最近更新 更多