Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how to enable or disable scrolling on FlatList

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.

like image 580
cityvoice Avatar asked Jul 19 '17 07:07

cityvoice


People also ask

Is FlatList scrollable?

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.

How do I get rid of FlatList scrollable React Native?

Conclusion. To hide the scrollbar in a FlatList with React Native in Android, we can set the showsVerticalScrollIndicator and showsHorizontalScrollIndicator props to false .

How do I make my screen scrollable in React Native?

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.


2 Answers

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 }) 
like image 172
Michael Cheng Avatar answered Sep 19 '22 06:09

Michael Cheng


You can save ref to FlatList and call setNativeProps on this ref:

this.flatList.setNativeProps({ scrollEnabled: false }) 
like image 31
Jan Mlčoch Avatar answered Sep 22 '22 06:09

Jan Mlčoch