[英]scroll FlatList in a ScrollView in React Native
I have a FlatList
inside a View
, and the View
is at the end of a ScrollView
, I want to scroll the FlatList
while the whole scroll at the end of the page. 我在View
内有一个FlatList
,而View
在ScrollView
的末尾,我想滚动FlatList
而整个滚动都在页面末尾。 But I can't do that. 但是我做不到。 So what should I do to let my FlatList
have the ability to scroll while inside a ScrollView
? 那么,如何使FlatList
能够在ScrollView
呢? The body is like this: 身体是这样的:
<ScrollView>
<View/>
<View/>
<View>
<View/>
<FlatList/>
</View>
</ScrollView>
You can solve this issue by adding some code in to View
which wraps the ScrollView
and the another View
which wraps the FlatList
您可以通过添加一些代码解决这个问题, View
包装了ScrollView
和另一View
包装了FlatList
So first of all define a user define variable in state
inside the constructor. 因此,首先在构造函数内部以state
定义用户定义变量。
this.state={
.....
enableScrollViewScroll : false
....
}
Then add following code as a props
to the View
which wrap the ScrollView
然后将以下代码作为props
添加到包装ScrollView
的View
中
onStartShouldSetResponderCapture={() => {
this.setState({ enableScrollViewScroll: true });
}}
Add scrollEnabled={this.state.enableScrollViewScroll}
prop to ScrollView
将scrollEnabled={this.state.enableScrollViewScroll}
添加到ScrollView
And Finally add following to the View which wraps the FlatList( immediate parent ) 最后,在包装FlatList(直接父对象)的View中添加以下内容
onStartShouldSetResponderCapture={() => {
this.setState({ enableScrollViewScroll: false });
if (this.refs.myList.scrollProperties.offset === 0 &&
this.state.enableScrollViewScroll === false) {
this.setState({ enableScrollViewScroll: true });
}
}}
Here myList
is the referance of FlatList
这里myList
是FlatList
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.