Permalink
Browse files

Support API "scrollTo" in RecyclerViewBackedScrollView on Android

Summary:
In Android `RecyclerViewBackedScrollView` didn't provide the `scrollTo` API, however iOS does.
If a ListView was created with `RecyclerViewBackedScrollView` as its `renderScrollComponent`, then calling `scrollTo` wouldn't work.

This diff enables the `scrollTo` API in `RecyclerViewBackedScrollView` on Android.

Reviewed By: dmmiller

Differential Revision: D3605233

fbshipit-source-id: f192053361f45453e5fce3fb6038ab03ac4025af
  • Loading branch information...
1 parent a07026d commit 235c059605c63f623b7f371db71d4182a63a828c @lebronJ lebronJ committed with Facebook Github Bot 8 Jul 22, 2016
Showing with 24 additions and 0 deletions.
  1. +24 −0 Libraries/Components/ScrollView/RecyclerViewBackedScrollView.android.js
@@ -75,6 +75,30 @@ var RecyclerViewBackedScrollView = React.createClass({
this.props.onContentSizeChange(width, height);
},
+ /**
+ * A helper function to scroll to a specific point in the scrollview.
+ * This is currently used to help focus on child textviews, but can also
+ * be used to quickly scroll to any element we want to focus. Syntax:
+ *
+ * scrollResponderScrollTo(options: {x: number = 0; y: number = 0; animated: boolean = true})
+ *
+ * Note: The weird argument signature is due to the fact that, for historical reasons,
+ * the function also accepts separate arguments as as alternative to the options object.
+ * This is deprecated due to ambiguity (y before x), and SHOULD NOT BE USED.
+ */
+ scrollTo: function(
+ y?: number | { x?: number, y?: number, animated?: boolean },
+ x?: number,
+ animated?: boolean
+ ) {
+ if (typeof y === 'number') {
+ console.warn('`scrollTo(y, x, animated)` is deprecated. Use `scrollTo({x: 5, y: 5, animated: true})` instead.');
+ } else {
+ ({x, y, animated} = y || {});
+ }
+ this.getScrollResponder().scrollResponderScrollTo({x: x || 0, y: y || 0, animated: animated !== false});
+ },
+
render: function() {
var recyclerProps = {
...this.props,

0 comments on commit 235c059

Please sign in to comment.