我在本周早些时候提出了一个与此类似的问题,并且取得了更多进展,所以我关闭了上一个并启动了这个问题,因为我也找不到解决方案。
this._scrollRef.scrollTo is not a function
at VirtualizedList.scrollToIndex
这是代码。
<AnimatedFlatList
ref={ (node) => { this._listRef = node; } }
style={[styles.picker, styles.scroll, pickerStyle]}
data={data}
renderItem={this.renderItems}
getItemLayout={(_, index) => (
{ length: 24, offset: 24 * index, index }
)}
initialNumToRender={5}
// scrollEnabled={visibleItemCount < itemCount}
contentContainerStyle={styles.scrollContainer}
scrollEventThrottle={2000}
keyExtractor={(item) => item.value}
automaticallyAdjustContentInsets={false}
removeClippedSubviews={false}
indicatorStyle="white"
/>
Run Code Online (Sandbox Code Playgroud)
在这一点上,我只是不确定为什么通话this._listRef.getNode().scrollToIndex(...params)不起作用。
一般来说,您需要更换
this._scrollRef.scrollTo(...)
Run Code Online (Sandbox Code Playgroud)
和
this._scrollRef.current.scrollTo(...)
Run Code Online (Sandbox Code Playgroud)
此处记录了这一点。
useRef 返回一个可变的 ref 对象,其 .current 属性被初始化为传递的参数 (initialValue)。返回的对象将在组件的整个生命周期内持续存在。
请注意,这getNode()已被弃用,并且对于文档中的动画组件来说不再是必需的所述。
摘要:进行了更改
createAnimatedComponent,以便ref分配给动画组件的分配现在将转发给内部组件。以前,使用该方法访问内部组件的引用getNode。该getNode方法现已弃用,并将返回相同的结果ref,但显示弃用错误。
| 归档时间: |
|
| 查看次数: |
827 次 |
| 最近记录: |