diff --git a/React/Fabric/Mounting/ComponentViews/ScrollView/RCTScrollViewComponentView.mm b/React/Fabric/Mounting/ComponentViews/ScrollView/RCTScrollViewComponentView.mm index dd0f4ce94e61a0..453312d85cde08 100644 --- a/React/Fabric/Mounting/ComponentViews/ScrollView/RCTScrollViewComponentView.mm +++ b/React/Fabric/Mounting/ComponentViews/ScrollView/RCTScrollViewComponentView.mm @@ -627,7 +627,7 @@ - (void)scrollToOffset:(CGPoint)offset animated:(BOOL)animated - (void)zoomToRect:(CGRect)rect animated:(BOOL)animated { - // Not implemented. + [_scrollView zoomToRect:rect animated:animated]; } - (void)addScrollListener:(NSObject *)scrollListener diff --git a/ReactCommon/react/renderer/components/scrollview/RCTComponentViewHelpers.h b/ReactCommon/react/renderer/components/scrollview/RCTComponentViewHelpers.h index ce4303c2c94afd..0fab3ae8160e68 100644 --- a/ReactCommon/react/renderer/components/scrollview/RCTComponentViewHelpers.h +++ b/ReactCommon/react/renderer/components/scrollview/RCTComponentViewHelpers.h @@ -15,6 +15,7 @@ NS_ASSUME_NONNULL_BEGIN - (void)flashScrollIndicators; - (void)scrollTo:(double)x y:(double)y animated:(BOOL)animated; - (void)scrollToEnd:(BOOL)animated; +- (void)zoomToRect:(CGRect)rect animated:(BOOL)animated; @end RCT_EXTERN inline void @@ -90,6 +91,43 @@ RCTScrollViewHandleCommand(id componentView, NSString con [componentView scrollToEnd:animated]; return; } + + if ([commandName isEqualToString:@"zoomToRect"]) { +#if RCT_DEBUG + if ([args count] != 2) { + RCTLogError( + @"%@ command %@ received %d arguments, expected %d.", @"ScrollView", commandName, (int)[args count], 2); + return; + } +#endif + + NSObject *arg0 = args[0]; + +#if RCT_DEBUG + if (!RCTValidateTypeOfViewCommandArgument( + arg0, [NSDictionary class], @"dictionary", @"ScrollView", commandName, @"1st")) { + return; + } +#endif + + NSDictionary *rectDict = (NSDictionary *)arg0; + NSNumber *x = rectDict[@"x"]; + NSNumber *y = rectDict[@"y"]; + NSNumber *width = rectDict[@"width"]; + NSNumber *height = rectDict[@"height"]; + CGRect rect = CGRectMake(x.doubleValue, y.doubleValue, width.doubleValue, height.doubleValue); + + NSObject *arg1 = args[1]; +#if RCT_DEBUG + if (!RCTValidateTypeOfViewCommandArgument(arg1, [NSNumber class], @"boolean", @"ScrollView", commandName, @"2nd")) { + return; + } +#endif + + BOOL animated = [(NSNumber *)arg1 boolValue]; + [componentView zoomToRect:rect animated:animated]; + return; + } } NS_ASSUME_NONNULL_END