I have a FlatList
which is wrapped in a View.
<View {...this._panResponder.panHandlers}> <FlatList .../> </View>
the View is a panResponder
, so how to disable FlatList's scrolling when onPanResponderGrant
triggers.
Under the hood, FlatList uses the ScrollView component to render scrollable elements. However, unlike generic ScrollView, FlatList displays data lazily to save memory and processing time.
Conclusion. To hide the scrollbar in a FlatList with React Native in Android, we can set the showsVerticalScrollIndicator and showsHorizontalScrollIndicator props to false .
well its pretty simple, just warp your components in <ScrollView> ... </ScrollView> and style it as per your need. if height of components together exceeds for <ScrollView> , it becomes scrollable.
The documentation states that a FlatList
has the props of a ScrollView
:
and thus inherits it's props (as well as those of ScrollView)
If you check the documentation for ScrollView
, you'll see that all you need to do is set the scrollEnabled
prop to false to disable scrolling. How and where you choose to do this will be up to you since you didn't really post any code. A simple way to handle this would be to use state:
<FlatList ... scrollEnabled={this.state.scrollEnabled} /> // Change the state to the appropriate value in onPanResponderGrant: // To enable: this.setState({ scrollEnabled: true }) // To disable: this.setState({ scrollEnabled: false })
You can save ref to FlatList and call setNativeProps on this ref:
this.flatList.setNativeProps({ scrollEnabled: false })
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With