From 93b39b73262f20f0d1ec96e0e33d7b4aaff6879b Mon Sep 17 00:00:00 2001 From: Li Jie Date: Sun, 17 Apr 2016 00:32:28 -0700 Subject: [PATCH] Fix refreshing state Summary:When RefreshControl.refreshing change twice within 250ms, it ignores the second changing. **Test plan (required)** ``` refresh () { this.setState({ refreshing: true }) fetch('/api') .then(() => { this.setState({ refreshing: false }) }) .catch((error) => { this.setState({ refreshing: false }) }) } render() { return ( }> Touch Me! ) } ``` * Test Case 1: Touch "Touch Me!", if get response less than 250ms, the state is always refreshing. * Test Case 2: Close network, Touch "Touch Me!", the state is always refreshing. Closes https://github.com/facebook/react-native/pull/6737 Differential Revision: D3189627 fb-gh-sync-id: 81c1932408e1ab99732b8340a5e3bd557629a66b fbshipit-source-id: 81c1932408e1ab99732b8340a5e3bd557629a66b --- React/Views/RCTRefreshControl.m | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/React/Views/RCTRefreshControl.m b/React/Views/RCTRefreshControl.m index a316246bc..a28078c10 100644 --- a/React/Views/RCTRefreshControl.m +++ b/React/Views/RCTRefreshControl.m @@ -14,6 +14,7 @@ @implementation RCTRefreshControl { BOOL _initialRefreshingState; BOOL _isInitialRender; + BOOL _currentRefreshingState; } - (instancetype)init @@ -21,6 +22,7 @@ if ((self = [super init])) { [self addTarget:self action:@selector(refreshControlValueChanged) forControlEvents:UIControlEventValueChanged]; _isInitialRender = true; + _currentRefreshingState = false; } return self; } @@ -105,7 +107,9 @@ RCT_NOT_IMPLEMENTED(- (instancetype)initWithCoder:(NSCoder *)aDecoder) - (void)setRefreshing:(BOOL)refreshing { - if (self.refreshing != refreshing) { + if (_currentRefreshingState != refreshing) { + _currentRefreshingState = refreshing; + if (refreshing) { // If it is the initial render, beginRefreshing will get called // in layoutSubviews. @@ -122,6 +126,8 @@ RCT_NOT_IMPLEMENTED(- (instancetype)initWithCoder:(NSCoder *)aDecoder) - (void)refreshControlValueChanged { + _currentRefreshingState = super.refreshing; + if (_onRefresh) { _onRefresh(nil); }