mirror of
https://github.com/zhigang1992/react-native.git
synced 2026-04-24 04:16:00 +08:00
Add UIManager.measureInWindow to get window coordinates
Summary: When embedding in a hybrid app, we sometimes present new modal views or windows that have a different frame from the original root view. This API allows us to get coordinates in the application's window frame, which should be valid in any fullscreen view. Reviewed By: majak Differential Revision: D2939827 fb-gh-sync-id: 06b93cc2cb3519a25819c6efa445c779314dd673 shipit-source-id: 06b93cc2cb3519a25819c6efa445c779314dd673
This commit is contained in:
committed by
Facebook Github Bot 4
parent
d94a56747d
commit
f67fa82008
@@ -1076,6 +1076,29 @@ RCT_EXPORT_METHOD(measure:(nonnull NSNumber *)reactTag
|
||||
}];
|
||||
}
|
||||
|
||||
RCT_EXPORT_METHOD(measureInWindow:(nonnull NSNumber *)reactTag
|
||||
callback:(RCTResponseSenderBlock)callback)
|
||||
{
|
||||
[self addUIBlock:^(__unused RCTUIManager *uiManager, NSDictionary<NSNumber *, UIView *> *viewRegistry) {
|
||||
UIView *view = viewRegistry[reactTag];
|
||||
if (!view) {
|
||||
// this view was probably collapsed out
|
||||
RCTLogWarn(@"measure cannot find view with tag #%@", reactTag);
|
||||
callback(@[]);
|
||||
return;
|
||||
}
|
||||
|
||||
// Return frame coordinates in window
|
||||
CGRect windowFrame = [view.window convertRect:view.frame fromView:view.superview];
|
||||
callback(@[
|
||||
@(windowFrame.origin.x),
|
||||
@(windowFrame.origin.y),
|
||||
@(windowFrame.size.width),
|
||||
@(windowFrame.size.height),
|
||||
]);
|
||||
}];
|
||||
}
|
||||
|
||||
static void RCTMeasureLayout(RCTShadowView *view,
|
||||
RCTShadowView *ancestor,
|
||||
RCTResponseSenderBlock callback)
|
||||
|
||||
Reference in New Issue
Block a user