Skip to content

Commit 19d4cc2

Browse files
sammy-SCfacebook-github-bot
authored andcommitted
Implement ScrollView.zoomToRect
Summary: Changelog: [internal] Reviewed By: JoshuaGross Differential Revision: D24991008 fbshipit-source-id: 6048246a784b94a321281547d966379badd8f6fd
1 parent cf97c1f commit 19d4cc2

File tree

2 files changed

+39
-1
lines changed

2 files changed

+39
-1
lines changed

React/Fabric/Mounting/ComponentViews/ScrollView/RCTScrollViewComponentView.mm

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -627,7 +627,7 @@ - (void)scrollToOffset:(CGPoint)offset animated:(BOOL)animated
627627

628628
- (void)zoomToRect:(CGRect)rect animated:(BOOL)animated
629629
{
630-
// Not implemented.
630+
[_scrollView zoomToRect:rect animated:animated];
631631
}
632632

633633
- (void)addScrollListener:(NSObject<UIScrollViewDelegate> *)scrollListener

ReactCommon/react/renderer/components/scrollview/RCTComponentViewHelpers.h

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ NS_ASSUME_NONNULL_BEGIN
1515
- (void)flashScrollIndicators;
1616
- (void)scrollTo:(double)x y:(double)y animated:(BOOL)animated;
1717
- (void)scrollToEnd:(BOOL)animated;
18+
- (void)zoomToRect:(CGRect)rect animated:(BOOL)animated;
1819
@end
1920

2021
RCT_EXTERN inline void
@@ -90,6 +91,43 @@ RCTScrollViewHandleCommand(id<RCTScrollViewProtocol> componentView, NSString con
9091
[componentView scrollToEnd:animated];
9192
return;
9293
}
94+
95+
if ([commandName isEqualToString:@"zoomToRect"]) {
96+
#if RCT_DEBUG
97+
if ([args count] != 2) {
98+
RCTLogError(
99+
@"%@ command %@ received %d arguments, expected %d.", @"ScrollView", commandName, (int)[args count], 2);
100+
return;
101+
}
102+
#endif
103+
104+
NSObject *arg0 = args[0];
105+
106+
#if RCT_DEBUG
107+
if (!RCTValidateTypeOfViewCommandArgument(
108+
arg0, [NSDictionary class], @"dictionary", @"ScrollView", commandName, @"1st")) {
109+
return;
110+
}
111+
#endif
112+
113+
NSDictionary *rectDict = (NSDictionary *)arg0;
114+
NSNumber *x = rectDict[@"x"];
115+
NSNumber *y = rectDict[@"y"];
116+
NSNumber *width = rectDict[@"width"];
117+
NSNumber *height = rectDict[@"height"];
118+
CGRect rect = CGRectMake(x.doubleValue, y.doubleValue, width.doubleValue, height.doubleValue);
119+
120+
NSObject *arg1 = args[1];
121+
#if RCT_DEBUG
122+
if (!RCTValidateTypeOfViewCommandArgument(arg1, [NSNumber class], @"boolean", @"ScrollView", commandName, @"2nd")) {
123+
return;
124+
}
125+
#endif
126+
127+
BOOL animated = [(NSNumber *)arg1 boolValue];
128+
[componentView zoomToRect:rect animated:animated];
129+
return;
130+
}
93131
}
94132

95133
NS_ASSUME_NONNULL_END

0 commit comments

Comments
 (0)