Skip to content
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

Closed
wants to merge 1 commit into from

Conversation

rigdern
Copy link
Contributor

@rigdern rigdern commented Aug 22, 2017

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 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.

Test Plan

In a test app, verified that scrollBy works properly with and without animation and for both horizontal and vertical ScrollViews. Also, my team is using this change in our app.

Adam Comella
Microsoft Corp.

@facebook-github-bot facebook-github-bot added CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed. GH Review: review-needed labels Aug 22, 2017
@shergin shergin self-requested a review August 23, 2017 05:04
@@ -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;
Copy link
Contributor

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 👍

Copy link
Contributor Author

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.
@rigdern rigdern force-pushed the rigdern/android-scrollBy branch from fb3fe2b to b2087ba Compare August 30, 2017 07:40
@rigdern
Copy link
Contributor Author

rigdern commented Aug 30, 2017

@AaaChiuuu, @achen1 can you review this PR or find an appropriate person to do so?

@shergin
Copy link
Contributor

shergin commented Aug 31, 2017

I have to mention here that same consideration described in #15609 are also applicable here.

@facebook-github-bot
Copy link
Contributor

@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.

@stale
Copy link

stale bot commented Dec 15, 2017

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.

@stale stale bot added the Stale There has been a lack of activity on this issue and it may be closed soon. label Dec 15, 2017
@rigdern
Copy link
Contributor Author

rigdern commented Dec 15, 2017

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.

@rigdern rigdern closed this Dec 15, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed. Stale There has been a lack of activity on this issue and it may be closed soon.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants