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
This commit is contained in:
Riccardo Cipolleschi
2024-04-12 08:08:19 -07:00
committed by Facebook GitHub Bot
parent 7131f94895
commit 18f0a90358
@@ -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<PullToRefreshViewComponentDescriptor>();
}
- (void)prepareForRecycle
{
[super prepareForRecycle];
_scrollViewComponentView = nil;
[self _initializeUIRefreshControl];
}
- (void)updateProps:(const Props::Shared &)props oldProps:(const Props::Shared &)oldProps
{
const auto &oldConcreteProps = static_cast<const PullToRefreshViewProps &>(*_props);
@@ -113,6 +124,7 @@ using namespace facebook::react;
- (void)didMoveToWindow
{
[super didMoveToWindow];
if (self.window) {
[self _attach];
} else {