From 7ee8dd788f01b5c44d29da2ccbb813b3c976fc2c Mon Sep 17 00:00:00 2001 From: Jakob Kerkhove Date: Tue, 6 Jun 2017 12:24:47 -0700 Subject: [PATCH] Expand documentation scroll to offset Summary: I expanded the documentation of the scrollToOffset method a bit in FlatList Thanks for submitting a PR! Please read these instructions carefully: - [x] Explain the **motivation** for making this change. - [x] Provide a **test plan** demonstrating that the code is solid. - [x] Match the **code formatting** of the rest of the codebase. - [x] Target the `master` branch, NOT a "stable" branch. The documentation of the scrollToOffset method in FlatList was a bit confusing. Also, there was no documentation for this method on VirtualizedList. I added the doc block there and linked to it from the FlatList doc block. Please check if the link on the FlatList scrollToOffset method links to the scrollToOffset method of the VirtualizedList docs page. Sign the [CLA][2], if you haven't already. Small pull requests are much easier to review and more likely to get merged. Make sure the PR does only one thing, otherwise please split it. Make sure all **tests pass** on both [Travis][3] and [Circle CI][4]. PRs that break tests are unlikely to be merged. For more info, see the ["Pull Requests"][5] section of our "Contributing" guidelines. [1]: https://medium.com/martinkonicek/what-is-a-test-plan-8bfc840ec171#.y9lcuqqi9 [2]: https://code.facebook.com/cla [3]: https://travis-ci.org/facebook/react-native [4]: http://circleci.com/gh/facebook/react-native [5]: https://github.com/facebook/react-native/blob/master/CONTRIBUTING.md#pull-requests Closes https://github.com/facebook/react-native/pull/14317 Differential Revision: D5192378 Pulled By: hramos fbshipit-source-id: 6131a8e5adb2a2f7cb84344541f4f8b999a232d2 --- Libraries/Lists/FlatList.js | 4 +++- Libraries/Lists/VirtualizedList.js | 10 ++++++++++ 2 files changed, 13 insertions(+), 1 deletion(-) diff --git a/Libraries/Lists/FlatList.js b/Libraries/Lists/FlatList.js index ea615d236..f95c86733 100644 --- a/Libraries/Lists/FlatList.js +++ b/Libraries/Lists/FlatList.js @@ -325,7 +325,9 @@ class FlatList extends React.PureComponent, vo } /** - * Scroll to a specific content pixel offset, like a normal `ScrollView`. + * Scroll to a specific content pixel offset in the list. + * + * Check out [scrollToOffset](docs/virtualizedlist.html#scrolltooffset) of VirtualizedList */ scrollToOffset(params: {animated?: ?boolean, offset: number}) { this._listRef.scrollToOffset(params); diff --git a/Libraries/Lists/VirtualizedList.js b/Libraries/Lists/VirtualizedList.js index 68aefe40e..936e748b9 100644 --- a/Libraries/Lists/VirtualizedList.js +++ b/Libraries/Lists/VirtualizedList.js @@ -238,6 +238,16 @@ class VirtualizedList extends React.PureComponent { } } + /** + * Scroll to a specific content pixel offset in the list. + * + * Param `offset` expects the offset to scroll to. + * In case of `horizontal` is true, the offset is the x-value, + * in any other case the offset is the y-value. + * + * Param `animated` (`true` by default) defines whether the list + * should do an animation while scrolling. + */ scrollToOffset(params: {animated?: ?boolean, offset: number}) { const {animated, offset} = params; this._scrollRef.scrollTo(