From 222875220fb497d80ab9b8152a35e34c71a931a5 Mon Sep 17 00:00:00 2001 From: Janic Duplessis Date: Sun, 1 May 2016 03:56:15 -0400 Subject: [PATCH] Fix RefreshControl race condition --- .../swiperefresh/ReactSwipeRefreshLayout.java | 17 +++++++++++++++++ .../swiperefresh/SwipeRefreshLayoutManager.java | 11 ++--------- 2 files changed, 19 insertions(+), 9 deletions(-) diff --git a/ReactAndroid/src/main/java/com/facebook/react/views/swiperefresh/ReactSwipeRefreshLayout.java b/ReactAndroid/src/main/java/com/facebook/react/views/swiperefresh/ReactSwipeRefreshLayout.java index f458c0ab06b914..728def66f7940b 100644 --- a/ReactAndroid/src/main/java/com/facebook/react/views/swiperefresh/ReactSwipeRefreshLayout.java +++ b/ReactAndroid/src/main/java/com/facebook/react/views/swiperefresh/ReactSwipeRefreshLayout.java @@ -20,10 +20,27 @@ */ public class ReactSwipeRefreshLayout extends SwipeRefreshLayout { + private boolean mRefreshing = false; + public ReactSwipeRefreshLayout(ReactContext reactContext) { super(reactContext); } + @Override + public void setRefreshing(boolean refreshing) { + if (mRefreshing != refreshing) { + mRefreshing = refreshing; + // Use `post` otherwise the control won't start refreshing if refreshing is true when + // the component gets mounted. + post(new Runnable() { + @Override + public void run() { + ReactSwipeRefreshLayout.super.setRefreshing(mRefreshing); + } + }); + } + } + @Override public boolean onInterceptTouchEvent(MotionEvent ev) { if (super.onInterceptTouchEvent(ev)) { 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 009f5a12650994..e158cd39ea87fc 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 @@ -71,15 +71,8 @@ public void setSize(ReactSwipeRefreshLayout view, int size) { } @ReactProp(name = "refreshing") - public void setRefreshing(final ReactSwipeRefreshLayout view, final boolean refreshing) { - // Use `post` otherwise the control won't start refreshing if refreshing is true when - // the component gets mounted. - view.post(new Runnable() { - @Override - public void run() { - view.setRefreshing(refreshing); - } - }); + public void setRefreshing(ReactSwipeRefreshLayout view, boolean refreshing) { + view.setRefreshing(refreshing); } @Override