-
Notifications
You must be signed in to change notification settings - Fork 24.4k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[ScrollView] Add support for nested scrollable views. #8024
Comments
👍 Beautiful issue. |
@facebook-github-bot label Good First Task |
I don't think that's a good first task @charpeni ? |
I agree, this will require some more significant changes in how we create scrollviews and dispatch scroll events. |
I'm running into this same issue. In iOS it seems to work as expected for me, but in Android the inner ScrollView never receives horizontal pan gestures if it is contained in a ScrollView that can also scroll horizontally, e.g. a zoomed image in a gallery |
@alloy just ran into this, any progress on the issue? |
The provided monkey-patch still works perfect in production with latest RN. I haven’t had much spare time to discuss and cleanup this patch until last week when we shipped a new major version of our app. @javache Can we catch-up sometime soon to talk it through? |
Guys, adding TouchableWithoutOpacity inside nested ScrollView worked like a charm for me on android: |
With |
@ilyadoroshin TouchableWithoutFeedback component worked for me on iOS. |
Has anyone other than @alloy found a workaround? Even if it's a monkeypatch approach, I am trying to resolve this. |
@ilyadoroshin @restlessCalm FYI The issue described in the linked SO post is about a completely different scenario than what this ticket is about. |
@AlanFoster @andrerfneves Did you try my monkey patches in latest RN and/or with FlatList? I haven’t upgrade to the latest yet, but the internal scrollview API hasn't’t changed much over the months, so should probably be ok. |
@alloy how would you go about using such monekypatches? Not entirely familiar with iOS development. My issue is actually the same but on the Android platform. Any thoughts? |
Ahh I see. No sorry I have no input on Android right now, only iOS. As to how to integrate these monkey patches, you can take a look at our OSS project they reside in. |
Any solution to nested scroll views on Android? |
Same here. Any workaround? i have something like this:
|
Greetings, For anyone looking for a workaround for android, I have a solution that was tested successfully. The core of the fix is to use NestedScollView instead of ScrollView. There's a library that already does this - https://github.com/mohtada-h/react-native-nested-scrollview, however it's not being maintained to support the latest RN. I've created a patch that can be applied directly from the root of a react native project. You can find the patch file here: https://raw.githubusercontent.com/hemantasapkota/react-native-nested-scrollview/master/root.patch Summary of the fix:
Final step would be to use NestedScrollView instead of ScrollView in your source project. |
@hemantasapkota hello dude, i get this error with your solution:
package.js
|
When scrollview is embedded in a item of Any help? thanks |
@jenskuhrjorgensen i'm experiencing the same issue!! Did you find any solution?? :( |
@rekha110254 Nope - I was so lucky that the design changed instead! 🍀 😄 |
@chetankotkar i'm experiencing same issue!! Did u find any solution? :/ |
@ashrithks ur method is buggy, it doesnt work after u scroll down and then go up. tried it on a real device. |
Anyone has the solution to this? I have to use nested FlatList inside ScrollView, but onEndReached keeps firing without reaching the end... |
Mine was ScrollView is rendered inside FlatList. The ScrollView scrolling effect doesnt work anymore but the FlatList is working fine. Any solution for this? |
This comment has been minimized.
This comment has been minimized.
I have found this nestedScrollEnabled but seems like its not working |
|
This comment has been minimized.
This comment has been minimized.
As pointed out in earlier comments, now nested scrolling is possible on both platforms via nestedScrollEnabled (which needs to be explicitly set for Android to use it, and as Ivan pointed out you need to have it set in the inner list). |
@kelset The OP is not about being able to scroll in nested scrollviews, though, that’s just something that many people have been discussing here but is off-topic. |
Hey @alloy thanks for the clarification, but then I'm confused by:
I mean, it seems to me that
Anyway I'll reopen :) |
Yeah it’s a nuanced issue 😄 It’s about having scrollviews inside a scrollview, which would disable the nested scrollviews from scrolling independently but still receive scroll events as if there were scrolling their own content. If you look at the GIF in the OP, you’ll see that per tab there’s only 1 large scrolling view, but there are actually some nested scrollviews in that hierarchy. |
I discussed this issue with @alloy in person. This is a valid proposal and definitely a change we'd like to have in React Native but over the course of almost three years nobody has put themselves forward to actually implement it and we haven't had a need for this at Facebook either, hence I'm going to close this issue. However, if you feel passionate about adding the right APIs without breaking existing code, please feel free to keep discussing the concrete implementation here and start sending PRs that gets us closer to the goal :) |
Try this, It worked for me |
For Discussion
In larger complex view hierarchies it may happen that a
ScrollView
-based component is nested inside anotherScrollView
.Currently a nested
ScrollView
won’t receive scroll events, only the outer parentScrollView
will. In order to receive them, you would have to push scroll event callbacks down each child component of the parentScrollView
and all of those would have to send them down to their children, just in case a component somewhere down the tree needs to receive such events.The developer and user of that component shouldn’t need to jump through hoops to have
ScrollView
callbacks work, but should be able to write isolated components that are unaware of the presence of otherScrollView
instances in the view hierarchy and have React Native deal with the details of dispatching events to all components that require them.Examples
Contrived
Multiple
ListView
instances as part of a larger scrolling view:Often the advice is to add views that are supposed to be above or below a
ListView
as a header or footer of theListView
, but that doesn’t solve the case where bothListView
instance have to scroll in tandem as part of the parentScrollView
.Real-world
My real world example is a ‘tab view’ component that displays a
ScrollView
-based component that needs to paginate.You can run the example app that’s contained in the repo to see it for yourself, or in our production app that is currently in the store, but here’s a short demonstration of the ‘WORKS’ grid component being nested inside the top-level
ScrollView
and still paginatingonEndReached
as expected:Proof of Concept
For my app I wrote some 🐒-patches that do the following:
RCTScrollView
is added to a view hierarchy, it registers for aRCTScrollEvent
notification.RCTScrollView
receives a native scroll callback it first does its own JS scroll event dispatching and afterwards it posts aRCTScrollEvent
notification for any childRCTScrollView
instances to pick-up.RCTScrollView
instance creates a newRCTScrollEvent
object that offsets the scrollview’scontentOffset
to reflect its location inside the parentRCTScrollView
.RCTScrollView
then dispatches the JS scroll event as normal and the component doesn’t know any better than that it has scrolled as normal.Notes:
NSNotificationCenter
because there’s a potential 1-to-many relationship. I haven’t noticed any discernible lag in delivery, but there’s also no guarantee. A possible alternative would be to use a proxy object as theUIScrollView
delegate that can dispatch events to multiple delegates (example).ListView
component in the current version of our app, I have tested and verified that theonEndReached
callback gets triggered, thus I see no reason why theremoveClippedSubviews
optimisation wouldn’t work either. At least that’s my goal, as I will need this soon.Discussion
ScrollView
into aScrollable
container. That container could then create theScrollView
if not inside a parentScrollView
./cc @javache @nicklockwood
The text was updated successfully, but these errors were encountered: