Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

React Native Touchable is disabling ScrollView

I'm new to React Native, so am probably asking something very obvious, but please help.

I have a view wrapped in a touchable, so that the whole area responds to tapping. Then have a ScrollView nested inside the view. The overall structure is something like this:

<TouchableWithoutFeedback onPress={this.handlePress.bind(this)}>     <View>         <ScrollView>             <Text>Hello, here is a very long text that needs scrolling.</Text>         <ScrollView>     </View> </TouchableWithoutFeedback> 

When this compiles and runs, the tapping is detected, but the scroll view doesn't scroll at all. I made the above code short and simple, but each component has the proper styling and I can see everything rendering fine and the long text is cutoff at the bottom of the ScrollView. Please help.

Thank you!

like image 874
Wonil Suh Avatar asked Oct 11 '15 02:10

Wonil Suh


People also ask

How do I disable Touchableopacity?

We will introduce how to disable the button in react. js using a disabled prop to our button element. To simply disable the button, we can use the disabled prop in our button element and set its value to true . If we want to disable our button after clicking on it, We can disable it by using react's state.

What is contentContainerStyle?

contentContainerStyle: It is used to style the content of the ScrollView containers. contentInset: This property is used to inset the scroll view content by a specific amount. contentInsetAdjustmentBehavior: This property is used to identify how the safe area insets are used to modify the content area of the ScrollView ...

How do you keep the scroll position using FlatList when navigating back in react native?

In Flatlist set scrollsToTop={false} this will retain position when you navigate back from detail screen.


2 Answers

This is what worked for me:

<TouchableWithoutFeedback onPress={...}>   <View>     <ScrollView>       <View onStartShouldSetResponder={() => true}>         // Scrollable content       </View>     </ScrollView>   </View> </TouchableWithoutFeedback> 

The onStartShouldSetResponder prop stops the touch event propagation towards the TouchableWithoutFeedback element.

like image 114
Rod Avatar answered Sep 21 '22 18:09

Rod


I'm using this structure it's working for me:  <TouchableWithoutFeedback onPress={() => {}}>     {other content}        <View onStartShouldSetResponder={() => true}>         <ScrollView>             {scrollable content}         </ScrollView>     </View> </TouchableWithoutFeedback> 
like image 39
elf2707 Avatar answered Sep 21 '22 18:09

elf2707