Skip to content

Commit

Permalink
Implement ScrollView.zoomToRect
Browse files Browse the repository at this point in the history
Summary: Changelog: [internal]

Reviewed By: JoshuaGross

Differential Revision: D24991008

fbshipit-source-id: 6048246a784b94a321281547d966379badd8f6fd
  • Loading branch information
sammy-SC authored and facebook-github-bot committed Nov 18, 2020
1 parent cf97c1f commit 19d4cc2
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -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<UIScrollViewDelegate> *)scrollListener
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -90,6 +91,43 @@ RCTScrollViewHandleCommand(id<RCTScrollViewProtocol> 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

0 comments on commit 19d4cc2

Please sign in to comment.