Skip to content

Commit db99668

Browse files
committed
Prefer using the same scrollResponderZoomTo with a second animated arg
1 parent 2069c6e commit db99668

File tree

2 files changed

+5
-28
lines changed

2 files changed

+5
-28
lines changed

Libraries/Components/ScrollResponder.js

Lines changed: 3 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -388,24 +388,13 @@ var ScrollResponderMixin = {
388388
/**
389389
* A helper function to zoom to a specific rect in the scrollview.
390390
* @param {object} rect Should have shape {x, y, width, height}
391+
* @param {bool} animated Enable the zoom animation
391392
*/
392-
scrollResponderZoomTo: function(rect: { x: number; y: number; width: number; height: number; }) {
393+
scrollResponderZoomTo: function(rect: { x: number; y: number; width: number; height: number; }, animated?: boolean = true) {
393394
if (Platform.OS === 'android') {
394395
invariant('zoomToRect is not implemented');
395396
} else {
396-
ScrollViewManager.zoomToRect(React.findNodeHandle(this), rect);
397-
}
398-
},
399-
400-
/**
401-
* A helper function to zoom to a specific rect in the scrollview without animation.
402-
* @param {object} rect Should have shape {x, y, width, height}
403-
*/
404-
scrollResponderZoomWithoutAnimationTo: function(rect: { x: number; y: number; width: number; height: number; }) {
405-
if (Platform.OS === 'android') {
406-
invariant('zoomToRect is not implemented');
407-
} else {
408-
ScrollViewManager.zoomToRectWithoutAnimation(React.findNodeHandle(this), rect);
397+
ScrollViewManager.zoomToRect(React.findNodeHandle(this), rect, animated);
409398
}
410399
},
411400

React/Views/RCTScrollViewManager.m

Lines changed: 2 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -152,30 +152,18 @@ - (UIView *)view
152152
}];
153153
}
154154

155-
RCT_EXPORT_METHOD(zoomToRect:(nonnull NSNumber *)reactTag withRect:(CGRect)rect)
155+
RCT_EXPORT_METHOD(zoomToRect:(nonnull NSNumber *)reactTag withRect:(CGRect)rect withAnimated:(BOOL)animated)
156156
{
157157
[self.bridge.uiManager addUIBlock:^(__unused RCTUIManager *uiManager, NSDictionary<NSNumber *, UIView *> *viewRegistry){
158158
UIView *view = viewRegistry[reactTag];
159159
if ([view conformsToProtocol:@protocol(RCTScrollableProtocol)]) {
160-
[(id<RCTScrollableProtocol>)view zoomToRect:rect animated:YES];
160+
[(id<RCTScrollableProtocol>)view zoomToRect:rect animated:animated];
161161
} else {
162162
RCTLogError(@"tried to zoomToRect: on non-RCTScrollableProtocol view %@ with tag #%@", view, reactTag);
163163
}
164164
}];
165165
}
166166

167-
RCT_EXPORT_METHOD(zoomToRectWithoutAnimation:(nonnull NSNumber *)reactTag withRect:(CGRect)rect)
168-
{
169-
[self.bridge.uiManager addUIBlock:^(__unused RCTUIManager *uiManager, NSDictionary<NSNumber *, UIView *> *viewRegistry){
170-
UIView *view = viewRegistry[reactTag];
171-
if ([view conformsToProtocol:@protocol(RCTScrollableProtocol)]) {
172-
[(id<RCTScrollableProtocol>)view zoomToRect:rect animated:NO];
173-
} else {
174-
RCTLogError(@"tried to zoomToRectWithoutAnimation: on non-RCTScrollableProtocol view %@ with tag #%@", view, reactTag);
175-
}
176-
}];
177-
}
178-
179167
- (NSArray<NSString *> *)customDirectEventTypes
180168
{
181169
return @[

0 commit comments

Comments
 (0)