-
Notifications
You must be signed in to change notification settings - Fork 24.4k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fix RefreshControl race condition #7317
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -20,10 +20,25 @@ | |
*/ | ||
public class ReactSwipeRefreshLayout extends SwipeRefreshLayout { | ||
|
||
private boolean mRefreshing = false; | ||
|
||
public ReactSwipeRefreshLayout(ReactContext reactContext) { | ||
super(reactContext); | ||
} | ||
|
||
@Override | ||
public void setRefreshing(boolean refreshing) { | ||
mRefreshing = refreshing; | ||
// Use `post` otherwise the control won't start refreshing if refreshing is true when | ||
// the component gets mounted. | ||
post(new Runnable() { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Not sure if it is good or bad but we have ReactSwipeRefreshLayout that posts a new Runnable with setRefreshing call while all the other Runnables are invoked from SwipeRefreshLayoutManager. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yeah, that other runnable was added pretty recently and the same bug could happen to that value too. I'll have another look at this tonight see if I can make this cleaner and make it consistent. |
||
@Override | ||
public void run() { | ||
ReactSwipeRefreshLayout.super.setRefreshing(mRefreshing); | ||
} | ||
}); | ||
} | ||
|
||
@Override | ||
public boolean onInterceptTouchEvent(MotionEvent ev) { | ||
if (super.onInterceptTouchEvent(ev)) { | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is this field useful?
It is read only once in the new Runnable below
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, the problem is when setRefreshing gets called twice in the same bridge transaction the order the runnables get executed is bad, see the example in the PR desc, adding the field makes sure is uses the latest value.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah, I see thanks, that makes sense.