Skip to content

Commit

Permalink
Fix refreshing state
Browse files Browse the repository at this point in the history
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 (
    <ScrollView
      refreshControl={
        <RefreshControl
          refreshing={this.state.refreshing}
          onRefresh={this.refresh.bind(this)}
        />
      }>
      <TouchableHighlight onPress={this.refresh.bind(this)}>
        <View>
          <Text>Touch Me!</Text>
        </View>
      </TouchableHighlight>
    </ScrollView>
  )
}
```

* 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 #6737

Differential Revision: D3189627

fb-gh-sync-id: 81c1932408e1ab99732b8340a5e3bd557629a66b
fbshipit-source-id: 81c1932408e1ab99732b8340a5e3bd557629a66b
  • Loading branch information
cpunion authored and Facebook Github Bot 2 committed Apr 17, 2016
1 parent 7851572 commit 93b39b7
Showing 1 changed file with 7 additions and 1 deletion.
8 changes: 7 additions & 1 deletion React/Views/RCTRefreshControl.m
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,15 @@
@implementation RCTRefreshControl {
BOOL _initialRefreshingState;
BOOL _isInitialRender;
BOOL _currentRefreshingState;
}

- (instancetype)init
{
if ((self = [super init])) {
[self addTarget:self action:@selector(refreshControlValueChanged) forControlEvents:UIControlEventValueChanged];
_isInitialRender = true;
_currentRefreshingState = false;
}
return self;
}
Expand Down Expand Up @@ -105,7 +107,9 @@ - (void)setTitleColor:(UIColor *)color

- (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.
Expand All @@ -122,6 +126,8 @@ - (void)setRefreshing:(BOOL)refreshing

- (void)refreshControlValueChanged
{
_currentRefreshingState = super.refreshing;

if (_onRefresh) {
_onRefresh(nil);
}
Expand Down

0 comments on commit 93b39b7

Please # to comment.