-
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
Custom Pagination on ScrollView Horizontal #1362
Comments
This is just how iOS behaves: size of scroll view viewport == one page. I don't believe it's possible to customize it, so if you want a different pagination distance, you'll have to change the size of your scroll view. |
Ok great. I think my best bet would be wrapping the scroll view in a container view whose job it is to intercept touches and hand them off to the scroll view? That way I can resize the scroll view while still being able to scroll outside of the scrollView. By the way RN changes the game. Awesome stuff. |
I guess then my question is how do I pass down touches to a child component. So how can I let the ScrollView inside of a View become the responder? |
I haven't thought about your specific use case but this documentation may provide helpful: https://facebook.github.io/react-native/docs/gesture-responder-system.html |
No worries, I think I came across a solution when I started looking at the source of the following react-native project => https://github.com/appintheair/react-native-looped-carousel/blob/master/index.js. By looking at the source I noticed a few properties not covered in the documentation for the ScrollView:
I don't see the events covered in the gesture-responder-system as well. Sorry if I am missing something. |
@TYRONEMICHAEL - I opened issue #1410 to address the documentation problems. Check out the ScrollResponder source for more info on these events - there are some pretty good comments documenting how they work. Also, let me know if you come up with custom horizontal ScrollView pager, would be curious to see your implementation - I'll need to do something like that myself soon. |
This is a very dirty implementation of snap scrolling, but maybe it will inspire someone to actually make it legit:
Issues with this:
|
@brentvatne I managed to get some pretty good scroll-snapping action going by adding some code to scrollViewWillEndDragging in RCTScrollView.m . As far as I can tell, it's bad news to try to take control of the scroll with JS once the ScrollView is moving. Jumping in to redirect the place where the contentOffset lands in the objective-c feels a million times nicer. Here's a video of it in action with different sizes and alignments: I'd definitely put together a pull request if this is something that might get considered for ScrollView. |
That is awesome. I would love to take a look how you implemented it in RCTScrollView. Do you have it up on a repo yet? Exactly what I was looking for. |
@rxb - that looks so cool! If you'd like to put together a PR for it, that would be much appreciated 😄 |
@brentvatne Awesome! I'll do it. Looks like ScrollView might be broken right now on master? Can't scroll even normally and getting a red outline around my ScrollView. @TYRONEMICHAEL You can see the additions here: master...rxb:snap . |
@rxb - try restarting Xcode and packager. if that doesn't fix it, vjeux/react-native#a5cabd17 works fine, just tried it |
@rxb - one thing I didn't see there in the video, can you cancel the snap by starting to scroll again? That's something that's very missed from the current snap implementation |
@rxb - including this in my newsletter this week 😄 |
@brentvatne Awesome! Is this the kind of thing you mean with the canceling? https://vid.me/O3wB @TYRONEMICHAEL Still having trouble with ScrollView on master. I'll dig in more to see if I can figure out what's up with that. |
@rxb - yeah, like that but also in the opposite direction - so if it starts to snap you can cancel it and scroll back |
@brentvatne How about this one: https://vid.me/yKVY |
@rxb - awesome 😄 |
@rxb But what if pagination is enabled and we just want to show only one next/prev card irrespective of scroll velocity. |
From the docs it does not seem possible to control the scrollView. The default behavior for pagination is the following:
Would it be possible to change this value to a custom value? Or would I need to extend the ScrollView and submit a PR.
The text was updated successfully, but these errors were encountered: