mirror of
https://github.com/zhigang1992/react-native.git
synced 2026-04-01 13:03:08 +08:00
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
This commit is contained in:
committed by
Facebook Github Bot 9
parent
2953a1a02e
commit
f7ce0c1c2f
@@ -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<ReactSwipeRefreshLayout> {
|
||||
|
||||
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<ReactSwipeRefres
|
||||
});
|
||||
}
|
||||
|
||||
@ReactProp(name = "progressViewOffset", defaultFloat = 0)
|
||||
public void setProgressViewOffset(final ReactSwipeRefreshLayout view, final float offset) {
|
||||
// Use `post` to get progress circle diameter properly
|
||||
// Otherwise returns 0
|
||||
view.post(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
int diameter = view.getProgressCircleDiameter();
|
||||
int start = Math.round(PixelUtil.toPixelFromDIP(offset)) - diameter;
|
||||
int end = Math.round(PixelUtil.toPixelFromDIP(offset + REFRESH_TRIGGER_DISTANCE));
|
||||
view.setProgressViewOffset(false, start, end);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void addEventEmitters(
|
||||
final ThemedReactContext reactContext,
|
||||
|
||||
Reference in New Issue
Block a user