Skip to content

Commit 09daad2

Browse files
cipolleschifacebook-github-bot
authored andcommitted
fix RefreshControl not refreshing on initial mount (#52615)
Summary: Pull Request resolved: #52615 The refresh control has some issues that this change addresses. - Issue with zIndex not propagating to RefreshControl. - Issue when RefreshControl being mounted as refreshing. - Issue with color props not applied ## Changelog: [iOS][Fixed] - Correctly propagate props to RefreshControl Reviewed By: sammy-SC Differential Revision: D76668478 fbshipit-source-id: c3a5ff04b1b2654d25c9053973c5cff0002a804a
1 parent b4a57dd commit 09daad2

1 file changed

Lines changed: 15 additions & 19 deletions

File tree

packages/react-native/React/Fabric/Mounting/ComponentViews/ScrollView/RCTPullToRefreshViewComponentView.mm

Lines changed: 15 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,6 @@ @interface RCTPullToRefreshViewComponentView () <RCTPullToRefreshViewViewProtoco
2424
@end
2525

2626
@implementation RCTPullToRefreshViewComponentView {
27-
BOOL _isBeforeInitialLayout;
2827
UIRefreshControl *_refreshControl;
2928
RCTScrollViewComponentView *__weak _scrollViewComponentView;
3029
}
@@ -36,8 +35,6 @@ - (instancetype)initWithFrame:(CGRect)frame
3635
// attaching and detaching of a pull-to-refresh view to a scroll view.
3736
// The pull-to-refresh view is not a subview of this view.
3837
self.hidden = YES;
39-
40-
_isBeforeInitialLayout = YES;
4138
[self _initializeUIRefreshControl];
4239
}
4340

@@ -63,19 +60,11 @@ - (void)prepareForRecycle
6360
{
6461
[super prepareForRecycle];
6562
_scrollViewComponentView = nil;
66-
_props = nil;
67-
_isBeforeInitialLayout = YES;
6863
[self _initializeUIRefreshControl];
6964
}
7065

7166
- (void)updateProps:(const Props::Shared &)props oldProps:(const Props::Shared &)oldProps
7267
{
73-
// Prop updates are ignored by _refreshControl until after the initial layout, so just store them in _props until then
74-
if (_isBeforeInitialLayout) {
75-
_props = std::static_pointer_cast<const PullToRefreshViewProps>(props);
76-
return;
77-
}
78-
7968
const auto &oldConcreteProps = static_cast<const PullToRefreshViewProps &>(*_props);
8069
const auto &newConcreteProps = static_cast<const PullToRefreshViewProps &>(*props);
8170

@@ -111,6 +100,10 @@ - (void)updateProps:(const Props::Shared &)props oldProps:(const Props::Shared &
111100
[_refreshControl endRefreshing];
112101
}
113102
}
103+
104+
if (newConcreteProps.zIndex != oldConcreteProps.zIndex) {
105+
_refreshControl.layer.zPosition = newConcreteProps.zIndex.value_or(0);
106+
}
114107
}
115108

116109
#pragma mark -
@@ -155,10 +148,12 @@ - (void)layoutSubviews
155148

156149
// Attempts to begin refreshing before the initial layout are ignored by _refreshControl. So if the control is
157150
// refreshing when mounted, we need to call beginRefreshing in layoutSubviews or it won't work.
158-
if (_isBeforeInitialLayout) {
159-
_isBeforeInitialLayout = NO;
151+
if (self.window) {
152+
const auto &concreteProps = static_cast<const PullToRefreshViewProps &>(*_props);
160153

161-
[self updateProps:_props oldProps:PullToRefreshViewShadowNode::defaultSharedProps()];
154+
if (concreteProps.refreshing) {
155+
[self beginRefreshingProgrammatically];
156+
}
162157
}
163158
}
164159

@@ -214,11 +209,12 @@ - (void)beginRefreshingProgrammatically
214209

215210
// When refreshing programmatically (i.e. without pulling down), we must explicitly adjust the ScrollView content
216211
// offset, or else the _refreshControl won't be visible
217-
UIScrollView *scrollView = _scrollViewComponentView.scrollView;
218-
CGPoint offset = {scrollView.contentOffset.x, scrollView.contentOffset.y - _refreshControl.frame.size.height};
219-
[scrollView setContentOffset:offset];
220-
221-
[_refreshControl beginRefreshing];
212+
if (!_refreshControl.isRefreshing) {
213+
UIScrollView *scrollView = _scrollViewComponentView.scrollView;
214+
CGPoint offset = {scrollView.contentOffset.x, scrollView.contentOffset.y - _refreshControl.frame.size.height};
215+
[scrollView setContentOffset:offset];
216+
[_refreshControl beginRefreshing];
217+
}
222218
}
223219

224220
#pragma mark - Native commands

0 commit comments

Comments
 (0)