javascript - 如何在本机反应中记录每次更新的动画值?
问题描述
我使用了 Animated Scrollview 并且正在使用我设置为 state 的in道具中的y
值来操作其他属性。我也设置了. 但是,我想在状态更新时检查 y 值。我该怎么做呢?如果有多种方法可以做到这一点,很高兴知道,因为我对此很陌生。我确实检查了 addListener 方法,但未能实现它,因为它只记录了初始值 0。我还检查了该方法,但是当设置为 true时它不起作用。contentOffset
onScroll
useNativeDriver to true
_getValue
useNativeDriver
您还可以共享资源或代码片段的链接,以供我参考。
如果我错过了问题中的任何细节,请告诉我。谢谢你。
我提到了这个例子:https ://stackoverflow.com/a/41934928/10841628
我的尝试:
state={ y:new Animated.Value(0) }
componentDidMount(){
this.state.y.addListener(({value}) => this._value = value)
}
componentDidUpdate(){
console.log(this.state.y._value)
}
和滚动视图:
<Animated.ScrollView
scrollEventThrottle={16}
showsVerticalScrollIndicator={false}
onScroll={Animated.event(
[
{
nativeEvent: {
contentOffset: { y }
}
}
],
{ useNativeDriver: true }
)}
/>
解决方案
推荐阅读
- python - 如何将 STL 文件转换为 numpy 数组并将其格式化以覆盖 Dicom 数据?
- python - python字符串转换为字典数组
- python - 从某个元素中删除子列表(python)
- ios - 如何在没有 pod 的情况下在 iOS 中设计概述的文本字段
- java - Java 中的示例 Ldap 套接字
- node.js - 尝试安装特定版本的 Express 时出现问题
- c++ - 枚举中的整数溢出,仅遍历命名整数
- javascript - 如何在 Typescript 中展平嵌套对象?
- seo - CLS 网络核心生命值让我抓狂
- apache - Lightsail 和 Letsencrypt - 不从 htdocs 文件夹渲染