@@ -41,12 +41,6 @@ - (void)layoutSubviews
41
41
{
42
42
[super layoutSubviews ];
43
43
44
- // Fix for bug #7976
45
- // TODO: Remove when updating to use iOS 10 refreshControl UIScrollView prop.
46
- if (self.backgroundColor == nil ) {
47
- self.backgroundColor = [UIColor clearColor ];
48
- }
49
-
50
44
// If the control is refreshing when mounted we need to call
51
45
// beginRefreshing in layoutSubview or it doesn't work.
52
46
if (_currentRefreshingState && _isInitialRender) {
@@ -59,34 +53,42 @@ - (void)beginRefreshingProgrammatically
59
53
{
60
54
UInt64 beginRefreshingTimestamp = _currentRefreshingStateTimestamp;
61
55
_refreshingProgrammatically = YES ;
62
- // When using begin refreshing we need to adjust the ScrollView content offset manually.
63
- UIScrollView *scrollView = (UIScrollView *)self.superview ;
56
+
64
57
// Fix for bug #24855
65
58
[self sizeToFit ];
66
- CGPoint offset = {scrollView. contentOffset . x , scrollView. contentOffset . y - self. frame . size . height };
67
-
68
- // `beginRefreshing` must be called after the animation is done. This is why it is impossible
69
- // to use `setContentOffset` with `animated:YES`.
70
- [UIView animateWithDuration: 0.25
71
- delay: 0
72
- options: UIViewAnimationOptionBeginFromCurrentState
73
- animations: ^( void ) {
74
- [scrollView setContentOffset: offset];
75
- }
76
- completion: ^(__unused BOOL finished) {
77
- if (beginRefreshingTimestamp == self-> _currentRefreshingStateTimestamp ) {
78
- [ super beginRefreshing ];
79
- [self setCurrentRefreshingState: super .refreshing ];
59
+
60
+ if (self. scrollView ) {
61
+ // When using begin refreshing we need to adjust the ScrollView content offset manually.
62
+ UIScrollView *scrollView = (UIScrollView *)self. scrollView ;
63
+
64
+ CGPoint offset = {scrollView. contentOffset . x , scrollView. contentOffset . y - self. frame . size . height };
65
+
66
+ // `beginRefreshing` must be called after the animation is done. This is why it is impossible
67
+ // to use `setContentOffset` with `animated:YES`.
68
+ [UIView animateWithDuration: 0.25
69
+ delay: 0
70
+ options: UIViewAnimationOptionBeginFromCurrentState
71
+ animations: ^( void ) {
72
+ [scrollView setContentOffset: offset ];
80
73
}
81
- }];
74
+ completion: ^(__unused BOOL finished) {
75
+ if (beginRefreshingTimestamp == self->_currentRefreshingStateTimestamp ) {
76
+ [super beginRefreshing ];
77
+ [self setCurrentRefreshingState: super .refreshing];
78
+ }
79
+ }];
80
+ } else if (beginRefreshingTimestamp == self->_currentRefreshingStateTimestamp ) {
81
+ [super beginRefreshing ];
82
+ [self setCurrentRefreshingState: super .refreshing];
83
+ }
82
84
}
83
85
84
86
- (void )endRefreshingProgrammatically
85
87
{
86
88
// The contentOffset of the scrollview MUST be greater than the contentInset before calling
87
89
// endRefreshing otherwise the next pull to refresh will not work properly.
88
- UIScrollView *scrollView = (UIScrollView *) self.superview ;
89
- if (_refreshingProgrammatically && scrollView.contentOffset .y < -scrollView.contentInset .top ) {
90
+ UIScrollView *scrollView = self.scrollView ;
91
+ if (scrollView && _refreshingProgrammatically && scrollView.contentOffset .y < -scrollView.contentInset .top ) {
90
92
UInt64 endRefreshingTimestamp = _currentRefreshingStateTimestamp;
91
93
CGPoint offset = {scrollView.contentOffset .x , -scrollView.contentInset .top };
92
94
[UIView animateWithDuration: 0.25
0 commit comments