-
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
Use contentOffset to set the starting scroll offset in ReactHorizontalScrollView #12502
Use contentOffset to set the starting scroll offset in ReactHorizontalScrollView #12502
Conversation
7403625
to
d81454b
Compare
Tests seem to be up and running again, I've rebased to see if they'll pass this time. |
To make it work on Android, do you mean I should use this method using ListView instead of ScrollView ? And is this also working for iOS ? |
|
What about |
Shouldn't take much to reproduce the same code there, my initial use case didn't include vertical so I didn't want to make a PR I wouldn't be testing, might do it over the weekend. |
I see the commit is submitted at Feb 27, 2017, is it available on any release version now? |
@BinLi-OW : This PR hasn't been merged in, so no, it isn't in any of the releases. You could apply the changes locally to have access to it and help test [if you do, please let me know of any bugs that pop up]. |
I have tested this a bit, and it appears to work. I have merged it into our product, it will be tested more throughout the week by myself and our QA team. |
@kkjamie : That's awesome, please let me know if you spot any issues! |
I actually just copied the file from this repo into my repo and renamed it, exposed it by a new Package. I don't want to be forking react-native and worrying about rebuilding, I know somebody at our company has done this. Checkout https://facebook.github.io/react-native/releases/next/docs/android-building-from-source.html |
I've just given this a try as I encountered the same problem, and can confirm that the change works as expected. |
@BinLi-OW I did it by forking, applying the changes of this commit, then building from source following the link @kkjamie posted above. |
This PR doesn't have a test plan, can you fix that? |
@hramos : I'll rebase it on master in the next few days and take a look at handling vertical ScrollViews as well. Any specific test suggestions? Would committing examples be enough? |
Hi! I've tried getting the vertical scroll to behave the same with great success! I did exactly the same as this patch does but in ReactHorizontalScrollView.java and ReactScrollView.java, dunno if you want to include it in your patch (would make more sense from a commit-perspective I guess) or if I should do this in a separate commit? Also, a word of warning - we had an included react-native component (seems to be react-native-scrollable-tab-view) that submits a contentOffset with only an x parameter. I think it's this line: https://github.com/skv-headless/react-native-scrollable-tab-view/blob/master/index.js#L155) This seems to be an illegal state if I understand the data-type PointPropType correctly, but I'm thinking it's a good thing to actually check that both properties are defined before trying to access them (our app crashed before I added validation that both properties are present). |
Summary: ScrollView does not support contentOffset on android (yet). Applying the patch in this PR: facebook#12502 But on the vertical component (ReactScrollView) fixes this. Test Plan: Use this patch on an app with a vertical ScrollView. Set contentOffset to something not default (x: 0, y: 0) and verify that content is scrolled on rendering. Reviewers: meros Reviewed By: meros Subscribers: jonas Maniphest Tasks: T42 Differential Revision: http://192.168.5.120.xip.io/D41
@xqwzts I tried to find reviewers for this pull request and wanted to ping them to take another look. However, based on the blame information for the files in this pull request I couldn't find any reviewers. This sometimes happens when the files in the pull request are new or don't exist on master anymore. Is this pull request still relevant? If yes could you please rebase? In case you know who has context on this code feel free to mention them in a comment (one person is fine). Thanks for reading and hope you will continue contributing to the project. |
This is the (evil) twin commit to: facebook#12502 Fixes that contentOffset is not available on Vertical scroll-views. Verification: * Create an Android component with a ScrollView. Add enough items to fill beyond the visible screen. Set the content offset to some value that makes the content scroll. Verify that it snaps to the y-axis as expected. * Remove items so screen is no longer filled, keep content offset parameter. Scroll view still works but does not scroll. * Set only one parameter to content-offset (x || y) - parameters are now ignored since they must be a pair. * Remove contentOffset, scrollView still works as before.
This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Maybe the issue has been fixed in a recent release, or perhaps it is not affecting a lot of people. If you think this issue should definitely remain open, please let us know why. Thank you for your contributions. |
@shergin Any chance to get this merged? Thanks. |
This is the (evil) twin commit to: facebook#12502 Fixes that contentOffset is not available on Vertical scroll-views. Verification: * Create an Android component with a ScrollView. Add enough items to fill beyond the visible screen. Set the content offset to some value that makes the content scroll. Verify that it snaps to the y-axis as expected. * Remove items so screen is no longer filled, keep content offset parameter. Scroll view still works but does not scroll. * Set only one parameter to content-offset (x || y) - parameters are now ignored since they must be a pair. * Remove contentOffset, scrollView still works as before.
@todorone it's been closed for over a year. It'd have a better chance if someone opened a new PR and applied the feedback from this thread. |
Implements
contentOffset
for horizontal scrollviews in Android [already implemented for ios]. This will allow specifying the position theScrollView
should start at.A common use case is having a horizontal
ListView
with pagingEnabled, and having it open to a specified page, without having to wait for it to load and then callscrollTo
.Also see #6849
Usage:
Add
contentOffset={{ x: someInitialXValue, y: someInitialYValue }}
to yourScrollView
props.Example: