From f7ce0c1c2fd2d6dacbf2c76cf43f48d245e8779d Mon Sep 17 00:00:00 2001 From: UnoDeTantos Date: Mon, 9 May 2016 01:50:48 -0700 Subject: [PATCH] Adds progressViewOffset to RefreshControl Summary: Add the possibility to define a progress view top offset to RefreshControl on android. As i comment in #6740, contentInset does the trick on IOS. Looking android documentation seems that exists a possible solution: http://developer.android.com/reference/android/support/v4/widget/SwipeRefreshLayout.html#setProgressViewOffset(boolean, int, int) This pull request implement that but keeping it simple, only a top offset. For example, now we could put navigation bar over the scrollview (or listview) and define a progressViewOffset on RefreshView in order to start behind the navigation. At this point we could make some kind of coordinator layout to hide/show navigation on scroll. To maintain the default behavior, start point is equal to start point minus progress circle diameter in order to create that progress circle before the start point. Closes https://github.com/facebook/react-native/pull/6759 Differential Revision: D3240664 Pulled By: mkonicek fb-gh-sync-id: ccf866272e871811c1c6dcc2a34f5c217967feee fbshipit-source-id: ccf866272e871811c1c6dcc2a34f5c217967feee --- .../RefreshControl/RefreshControl.js | 5 +++++ .../PullToRefreshViewAndroid.android.js | 6 ++++++ .../SwipeRefreshLayoutManager.java | 18 ++++++++++++++++++ 3 files changed, 29 insertions(+) diff --git a/Libraries/Components/RefreshControl/RefreshControl.js b/Libraries/Components/RefreshControl/RefreshControl.js index 59b127461ef..81cecb093f4 100644 --- a/Libraries/Components/RefreshControl/RefreshControl.js +++ b/Libraries/Components/RefreshControl/RefreshControl.js @@ -122,6 +122,11 @@ const RefreshControl = React.createClass({ * @platform android */ size: React.PropTypes.oneOf(RefreshLayoutConsts.SIZE.DEFAULT, RefreshLayoutConsts.SIZE.LARGE), + /** + * Progress view top offset + * @platform android + */ + progressViewOffset: React.PropTypes.number, }, _nativeRef: (null: any), diff --git a/Libraries/PullToRefresh/PullToRefreshViewAndroid.android.js b/Libraries/PullToRefresh/PullToRefreshViewAndroid.android.js index d1e2cf5d409..ea7d5e25c41 100644 --- a/Libraries/PullToRefresh/PullToRefreshViewAndroid.android.js +++ b/Libraries/PullToRefresh/PullToRefreshViewAndroid.android.js @@ -48,6 +48,11 @@ var PullToRefreshViewAndroid = React.createClass({ * The background color of the refresh indicator */ progressBackgroundColor: ColorPropType, + /** + * Progress view top offset + * @platform android + */ + progressViewOffset: React.PropTypes.number, /** * Whether the view should be indicating an active refresh */ @@ -80,6 +85,7 @@ var PullToRefreshViewAndroid = React.createClass({ progressBackgroundColor={this.props.progressBackgroundColor} ref={NATIVE_REF} refreshing={this.props.refreshing} + progressViewOffset={this.props.progressViewOffset} size={this.props.size} style={this.props.style}> {onlyChild(this.props.children)} diff --git a/ReactAndroid/src/main/java/com/facebook/react/views/swiperefresh/SwipeRefreshLayoutManager.java b/ReactAndroid/src/main/java/com/facebook/react/views/swiperefresh/SwipeRefreshLayoutManager.java index 009f5a12650..5db04a1a77f 100644 --- a/ReactAndroid/src/main/java/com/facebook/react/views/swiperefresh/SwipeRefreshLayoutManager.java +++ b/ReactAndroid/src/main/java/com/facebook/react/views/swiperefresh/SwipeRefreshLayoutManager.java @@ -20,6 +20,7 @@ import android.support.v4.widget.SwipeRefreshLayout.OnRefreshListener; import com.facebook.react.bridge.ReadableArray; import com.facebook.react.common.MapBuilder; import com.facebook.react.common.SystemClock; +import com.facebook.react.uimanager.PixelUtil; import com.facebook.react.uimanager.ThemedReactContext; import com.facebook.react.uimanager.UIManagerModule; import com.facebook.react.uimanager.ViewGroupManager; @@ -32,6 +33,8 @@ import com.facebook.react.uimanager.annotations.ReactProp; */ public class SwipeRefreshLayoutManager extends ViewGroupManager { + public static final float REFRESH_TRIGGER_DISTANCE = 48; + @Override protected ReactSwipeRefreshLayout createViewInstance(ThemedReactContext reactContext) { return new ReactSwipeRefreshLayout(reactContext); @@ -82,6 +85,21 @@ public class SwipeRefreshLayoutManager extends ViewGroupManager