29

I have the problem about nested scrollview on Android Device, but IOS OK

How to fix the issue about B scrollview cant scrolling ?

<ScrollView>  // A ScrollView
    <View><Text>Hello</Text></View> 
    <View><Text>Hello</Text></View> 
    <View><Text>Hello</Text></View> 
    <View><Text>Hello</Text></View> 
    <View>       
        <ScrollView> // B ScrollView
            <View><Text>Hello</Text></View>         
            <View><Text>Hello</Text></View>         
            <View><Text>Hello</Text></View>          
            <View><Text>Hello</Text></View>      
        </ScrollView> 
    </View>
</ScrollView>

6 Answers 6

85

If API 21 as minimum target is an option, you could upgrade to react-native 0.56.x and try the new prop nestedScrollEnabled.

Note: it is meant to be used in the child scrollview, i.e.

<ScrollView {...parentProps}>
  <ScrollView {...childProps} nestedScrollEnabled={true}>
  </ScrollView>
</ScrollView>
Sign up to request clarification or add additional context in comments.

8 Comments

Dear Alberto, I have a horizontal ScrollView which contains another horizontal scrollView, I've tried your solution but it doesn't work on android. Any idea?
Nested horizontal ScrollViews are confirmed to not work on Android - see snack.expo.io/@harrytravelchime/827f87 for an example. In fact, this is a big problem even with the native components: stackoverflow.com/questions/44798354/…
Dude, after 3 days of trying to get a scrollable drag-and-drop to work inside a ScrollView container, u just saved my life.
I wish I could upvote multiple times... thank you it works
It fixed, but I didn't understand how it worked as in doc it says by default it is true reactnative.dev/docs/scrollview#nestedscrollenabled-android
|
18

Add "nestedScrollEnabled={true}" property to the internal ScrollView and it will work as expected.

Comments

3

React-native ScrollView component uses Android ScrollView when you run app in android.

Android ScrollView doesn't support nested scrolling by default. You need to use NestedScrollView to achieve nested scrolling in android.

5 Comments

thanks, but how to use NestedScrollView in my react native case ?
Sorry, i still not understand about coustom native ui for android doc, would you like to explain more about my case ?
Is it can solve my case with using custom native ui NestedScrollView ? I dont know where to create custom viewManager class file.
This doesn't work for me. Could you take a look here? stackoverflow.com/questions/63437251/…
2

https://gist.github.com/ashrithks/8d97f928d92643468a26e29c4d2dbb67

try the above , expo link:- https://snack.expo.io/S11vIpHA-

hacky way

3 Comments

Your way works, but there is a problem when setting the wrapper view that wraps the nested scrollview to flex view and changing the height of the nested scrollview to 700 or any height that would show in fullscreen only the nested view and scroll all the end of the scrollview you will not scroll up again. You can see edited code: snack.expo.io/SJYzbXGmV
@0x01Brain , use facebook.github.io/react-native/docs/0.57/… supported by react-native now
@AshrithKS <ScrollView nestedScrollEnabled> worked 2022 thanks
0

In ScrollView, set style of contentContainerStyle to flex: 1:

<ScrollView>  // A ScrollView
    <View><Text>Hello</Text></View> 
    <View><Text>Hello</Text></View> 
    <View><Text>Hello</Text></View> 
    <View><Text>Hello</Text></View> 
    <View>       
        <ScrollView contentContainerStyle={{flex:1}}> // B ScrollView
            <View><Text>Hello</Text></View>         
            <View><Text>Hello</Text></View>         
            <View><Text>Hello</Text></View>          
            <View><Text>Hello</Text></View>      
        </ScrollView> 
    </View>
</ScrollView>

It worked for me on android. Let me know if it works for you please.

2 Comments

This doesn't work for me. Could you take a look here? stackoverflow.com/questions/63437251/…
Same here, It's not working for me.
0

I was also facing the same issue, I had verticle scroll and inside verticle scroll. I made a state and give the scrollEnabled to the outer scrollview and inside added the onTouchStart,onTouchEnd and onTouchCancel functions and change the state of the outer scroll to false so I can easily scroll. you can also try the same approach with ref

const [scroll, setScroll] = useState(true);

<ScrollView scrollEnabled={scroll}>
  ... other components
 <ScrollView 
  onTouchStart={ => setScroll(false)}
  onTouchEnd={ => setScroll(true)}
  onTouchCancel={ => setScroll(true)}
 >
 ... inside other components
 </ScrollView>
 ... other components 
</ScrollView>

1 Comment

doesn't seem to work properly when the user touch is fast

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.