From 19d468fed966f2adb973ad3f19a97a5ec0372e3a Mon Sep 17 00:00:00 2001 From: tutejsy Date: Thu, 26 Sep 2024 05:58:54 -0700 Subject: [PATCH] Fix applying of tintColor and progressViewOffset props for RefreshControl component (#46628) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Summary: While developing my project with New Architecture enabled I've found out that properties `tintColor` and `progressViewOffset` of component `RefreshControl` don't apply on iOS. This happens due to the lack of handling of these properties in the `RCTPullToRefreshViewComponentView.mm` class. The bug can be easily reproduced in RNTester app on RefreshControlExample.js screen, since it has property `tintColor="#ff0000"` (Red color), but RefreshControl renders with gray color: RefreshControlExample.js gray Refresh Control

This PR is opened to fix that by applying `tintColor` and `progressViewOffset` props to `_refreshControl` in `RCTPullToRefreshViewComponentView.mm` class. Fixes https://github.com/facebook/react-native/pull/46628 ## Changelog: [IOS][FIXED] - Fix applying of tintColor and progressViewOffset props for RefreshControl component with New Architecture enabled Pull Request resolved: https://github.com/facebook/react-native/pull/46628 Test Plan: 1. Run rn-tester app with New Architecture enabled on iOS 2. Open screen of RefreshControl component: Снимок экрана 2024-09-24 в 19 48 49 3. Open `/packages/rn-tester/js/examples/RefreshControl/RefreshControlExample.js` file and change properties `tintColor` and `progressViewOffset` of RefreshControl components on the line 85: Снимок экрана 2024-09-24 в 22 01 19 4. check that your changes applied: Снимок экрана 2024-09-24 в 19 54 46 Reviewed By: cortinico Differential Revision: D63381050 Pulled By: cipolleschi fbshipit-source-id: 4f3aed8bd7a1e42ce2a75aa19740fd8be1623c86 --- .../RCTPullToRefreshViewComponentView.mm | 22 +++++++++++++++++++ 1 file changed, 22 insertions(+) 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 86f3f578a7aa7e..704b2e95ec4730 100644 --- a/packages/react-native/React/Fabric/Mounting/ComponentViews/ScrollView/RCTPullToRefreshViewComponentView.mm +++ b/packages/react-native/React/Fabric/Mounting/ComponentViews/ScrollView/RCTPullToRefreshViewComponentView.mm @@ -49,6 +49,11 @@ - (void)_initializeUIRefreshControl [_refreshControl addTarget:self action:@selector(handleUIControlEventValueChanged) forControlEvents:UIControlEventValueChanged]; + + const auto &concreteProps = static_cast(*_props); + + _refreshControl.tintColor = RCTUIColorFromSharedColor(concreteProps.tintColor); + [self _updateProgressViewOffset:concreteProps.progressViewOffset]; } #pragma mark - RCTComponentViewProtocol @@ -78,6 +83,14 @@ - (void)updateProps:(const Props::Shared &)props oldProps:(const Props::Shared & } } + if (newConcreteProps.tintColor != oldConcreteProps.tintColor) { + _refreshControl.tintColor = RCTUIColorFromSharedColor(newConcreteProps.tintColor); + } + + if (newConcreteProps.progressViewOffset != oldConcreteProps.progressViewOffset) { + [self _updateProgressViewOffset:newConcreteProps.progressViewOffset]; + } + BOOL needsUpdateTitle = NO; if (newConcreteProps.title != oldConcreteProps.title) { @@ -102,6 +115,15 @@ - (void)handleUIControlEventValueChanged static_cast(*_eventEmitter).onRefresh({}); } +- (void)_updateProgressViewOffset:(Float)progressViewOffset +{ + _refreshControl.bounds = CGRectMake( + _refreshControl.bounds.origin.x, + -progressViewOffset, + _refreshControl.bounds.size.width, + _refreshControl.bounds.size.height); +} + - (void)_updateTitle { const auto &concreteProps = static_cast(*_props);