【发布时间】:2019-07-01 15:56:52
【问题描述】:
我在 HomeScreen 中使用 Flatlist,它显示了多个帖子。所以现在我想要的是每当我从应用程序注销或关闭应用程序然后打开应用程序时,我应该能够看到来自Flatlist 的第一项。
我尝试在我的渲染函数中使用scrollToIndex,但它给了我一个错误 - undefined is not an object (evaluating '_this2.refs.flatListRef.scrollToIndex')
<FlatList
data={this.state.data}
ref={(ref) => { this.flatListRef = ref; }}
renderItem={ ({item,index}) => this._renderItem(item,index) }
extraData={[ this.state.data, this.state.checked ]}
/>
这就是我在componentDidMount 和内部渲染函数this.refs.flatListRef.scrollToIndex({animated: true,index:0}); 中尝试使用的,但没有奏效。
【问题讨论】:
-
this.flatListRef.scrollToIndex({animated: true,index:0})应该修复它,因为您使用 ref 作为回调。 -
@PritishVaidya 我尝试在 Flatlist 的渲染函数中使用它,但它仍然无法正常工作
标签: android reactjs react-native react-native-flatlist