RefreshControl doesn't render when initial refreshing state is true

Summary:
Example (index.ios.js):

```
'use strict';

import React from 'react';
import {ListView, RefreshControl, Text, View} from 'react-native';

class BugExample extends React.Component {

    render() {
        return (
            <ListView
                style={{backgroundColor: 'red'}}
                contentContainerStyle={{backgroundColor: 'green'}}
                refreshControl={
                    <RefreshControl
                        refreshing={true}
                        onRefresh={() => {}}
                    />
                }
                dataSource={
                    new ListView.DataSource({rowHasChanged: (r1, r2) => r1 !== r2}).cloneWithRows(['a', 'b', 'c'])
                }
                renderRow={(item) => {
                    return (
                        <View>
                            <Text>{item}</Text>
                        </View>
                    );
                }}
            />
        );
    }
}
```

RN version: 0.34, 0.35-rc
iOS version (emulator): 9.
Closes https://github.com/facebook/react-native/pull/10321

Differential Revision: D4142774

Pulled By: mmmulani

fbshipit-source-id: 743b865a6e1c1fb09c7cfc48631ad383bd593f89
This commit is contained in:
Aleksei Androsov 2016-11-07 15:51:21 -08:00 committed by Facebook Github Bot
parent 4d35f65eb7
commit 3eeaffce1a
1 changed files with 6 additions and 16 deletions

View File

@ -12,7 +12,6 @@
#import "RCTUtils.h"
@implementation RCTRefreshControl {
BOOL _initialRefreshingState;
BOOL _isInitialRender;
BOOL _currentRefreshingState;
}
@ -41,7 +40,7 @@ RCT_NOT_IMPLEMENTED(- (instancetype)initWithCoder:(NSCoder *)aDecoder)
// If the control is refreshing when mounted we need to call
// beginRefreshing in layoutSubview or it doesn't work.
if (_currentRefreshingState && _isInitialRender && _initialRefreshingState) {
if (_currentRefreshingState && _isInitialRender) {
[self beginRefreshing];
}
_isInitialRender = false;
@ -52,14 +51,10 @@ RCT_NOT_IMPLEMENTED(- (instancetype)initWithCoder:(NSCoder *)aDecoder)
// When using begin refreshing we need to adjust the ScrollView content offset manually.
UIScrollView *scrollView = (UIScrollView *)self.superview;
CGPoint offset = {scrollView.contentOffset.x, scrollView.contentOffset.y - self.frame.size.height};
// Don't animate when the prop is set initialy.
if (_isInitialRender) {
scrollView.contentOffset = offset;
[super beginRefreshing];
} else {
// `beginRefreshing` must be called after the animation is done. This is why it is impossible
// to use `setContentOffset` with `animated:YES`.
[UIView animateWithDuration:0.25
// `beginRefreshing` must be called after the animation is done. This is why it is impossible
// to use `setContentOffset` with `animated:YES`.
[UIView animateWithDuration:0.25
delay:0
options:UIViewAnimationOptionBeginFromCurrentState
animations:^(void) {
@ -67,7 +62,6 @@ RCT_NOT_IMPLEMENTED(- (instancetype)initWithCoder:(NSCoder *)aDecoder)
} completion:^(__unused BOOL finished) {
[super beginRefreshing];
}];
}
}
- (void)endRefreshing
@ -117,11 +111,7 @@ RCT_NOT_IMPLEMENTED(- (instancetype)initWithCoder:(NSCoder *)aDecoder)
_currentRefreshingState = refreshing;
if (refreshing) {
// If it is the initial render, beginRefreshing will get called
// in layoutSubviews.
if (_isInitialRender) {
_initialRefreshingState = refreshing;
} else {
if (!_isInitialRender) {
[self beginRefreshing];
}
} else {