From 18f0a90358b4e7eb59871cc11a88ef9bef575246 Mon Sep 17 00:00:00 2001 From: Riccardo Cipolleschi Date: Fri, 12 Apr 2024 08:08:19 -0700 Subject: [PATCH] Properly recycle RCTPullToRefreshViewcomponentView (#44047) Summary: Pull Request resolved: https://github.com/facebook/react-native/pull/44047 This change properly recycles the RCTPullToRefreshViewComponentView so that it fixes some misbehaviors of the UIRefreshControl in OSS. This should fix https://github.com/facebook/react-native/issues/37308 and https://github.com/facebook/react-native/issues/36173 ## Changelog: [iOS][Fixed] - Properly recycle the RCTPullToRefreshViewComponentView Reviewed By: sammy-SC Differential Revision: D56018924 fbshipit-source-id: 3c71328aa0f6fb2a98a19593f0f06419e04e9cae --- .../RCTPullToRefreshViewComponentView.mm | 22 ++++++++++++++----- 1 file changed, 17 insertions(+), 5 deletions(-) diff --git a/packages/react-native/React/Fabric/Mounting/ComponentViews/ScrollView/RCTPullToRefreshViewComponentView.mm b/packages/react-native/React/Fabric/Mounting/ComponentViews/ScrollView/RCTPullToRefreshViewComponentView.mm index 64b09228a39..86f3f578a7a 100644 --- a/packages/react-native/React/Fabric/Mounting/ComponentViews/ScrollView/RCTPullToRefreshViewComponentView.mm +++ b/packages/react-native/React/Fabric/Mounting/ComponentViews/ScrollView/RCTPullToRefreshViewComponentView.mm @@ -37,16 +37,20 @@ using namespace facebook::react; self.hidden = YES; _props = PullToRefreshViewShadowNode::defaultSharedProps(); - - _refreshControl = [UIRefreshControl new]; - [_refreshControl addTarget:self - action:@selector(handleUIControlEventValueChanged) - forControlEvents:UIControlEventValueChanged]; + [self _initializeUIRefreshControl]; } return self; } +- (void)_initializeUIRefreshControl +{ + _refreshControl = [UIRefreshControl new]; + [_refreshControl addTarget:self + action:@selector(handleUIControlEventValueChanged) + forControlEvents:UIControlEventValueChanged]; +} + #pragma mark - RCTComponentViewProtocol + (ComponentDescriptorProvider)componentDescriptorProvider @@ -54,6 +58,13 @@ using namespace facebook::react; return concreteComponentDescriptorProvider(); } +- (void)prepareForRecycle +{ + [super prepareForRecycle]; + _scrollViewComponentView = nil; + [self _initializeUIRefreshControl]; +} + - (void)updateProps:(const Props::Shared &)props oldProps:(const Props::Shared &)oldProps { const auto &oldConcreteProps = static_cast(*_props); @@ -113,6 +124,7 @@ using namespace facebook::react; - (void)didMoveToWindow { + [super didMoveToWindow]; if (self.window) { [self _attach]; } else {