-
Notifications
You must be signed in to change notification settings - Fork 24.5k
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
Android ScrollView: Add scrollBy method #15610
Conversation
@@ -26,10 +26,12 @@ | |||
|
|||
public static final int COMMAND_SCROLL_TO = 1; | |||
public static final int COMMAND_SCROLL_TO_END = 2; | |||
public static final int COMMAND_SCROLL_BY = 3; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just for visibility; I've also changed this file: https://github.com/facebook/react-native/pull/15566/files#diff-0e688b19a3a45a0d17cd8d922cc0580aR29
If that makes its way into the code-base, there may be a small rebase required 👍
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@AlanFoster thanks for the heads up.
Currently, React Native allows you to scroll a ScrollView to a particular position using `scrollTo`. If instead you want to scroll by a delta, you could try to do this using `scrollTo` (add the delta to the current scroll position) but this doesn't always work out as intended due to the async nature of React Native (what you think is the current scroll position might be a stale value). This change introduces a `scrollBy` API to solve this problem. `scrollBy` takes a delta to scroll by and native takes care of doing the arithmetic because it knows the latest scroll position.
fb3fe2b
to
b2087ba
Compare
@AaaChiuuu, @achen1 can you review this PR or find an appropriate person to do so? |
I have to mention here that same consideration described in #15609 are also applicable here. |
@rigdern 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 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. |
Thanks for the discussion. We decided to go with an alternative solution. We built a native module which combines a number of operations our virtual list view implementation requires (e.g. scrolling & repositioning items) into a single method so all of the operations are completed in the same frame. |
iOS PR: #15609
Currently, React Native allows you to scroll a ScrollView to a particular position using
scrollTo
. If instead you want to scroll by a delta, you could try to do this usingscrollTo
(add the delta to the current scroll position) but this doesn't always work out as intended due to the async nature of React Native (what you think is the current scroll position might be a stale value). This change introduces ascrollBy
API to solve this problem.scrollBy
takes a delta to scroll by and native takes care of doing the arithmetic because it knows the latest scroll position.Test Plan
In a test app, verified that
scrollBy
works properly with and without animation and for both horizontal and verticalScrollViews
. Also, my team is using this change in our app.Adam Comella
Microsoft Corp.