diff --git a/renderer/native/ios/renderer/component/view/HippyViewManager.mm b/renderer/native/ios/renderer/component/view/HippyViewManager.mm index 3f52bed3a93..6d0f509fa38 100644 --- a/renderer/native/ios/renderer/component/view/HippyViewManager.mm +++ b/renderer/native/ios/renderer/component/view/HippyViewManager.mm @@ -188,28 +188,29 @@ - (void)measureInAppWindow:(NSNumber *)componentTag HIPPY_EXPORT_METHOD(getViewTagByLocation:(nonnull NSNumber *)componentTag params:(NSDictionary *__nonnull)params callback:(HippyPromiseResolveBlock)callback) { - [self.bridge.uiManager addUIBlock:^(__unused HippyUIManager *uiManager, NSDictionary *viewRegistry) { - NSMutableDictionary *locationDict = [NSMutableDictionary dictionaryWithDictionary:@{ - HippyTagKey: @(InvalidTag), + [self.bridge.uiManager addUIBlock:^(__unused HippyUIManager *uiManager, NSDictionary *viewRegistry) { + NSMutableDictionary *locationDict = [NSMutableDictionary dictionaryWithDictionary:@{ + HippyTagKey: @(InvalidTag), + }]; + UIView *view = viewRegistry[componentTag]; + if (view == nil) { + callback(locationDict); + return; + } + UIView *rootView = viewRegistry[view.rootTag]; + if (rootView == nil) { + callback(locationDict); + return; + } + double locationX = [params[HippyXOnScreenKey] doubleValue]; + double locationY = [params[HippyYOnScreenKey] doubleValue]; + UIView* hitView = [rootView hitTest:{locationX, locationY} withEvent:nil]; + // TODO: The hitView may not a hippy view (such as a sub native view). Should trace to hippy view. + if (hitView.hippyTag) { + [locationDict setObject:hitView.hippyTag forKey:HippyTagKey]; + } + callback(@[locationDict]); }]; - UIView *view = viewRegistry[componentTag]; - if (view == nil) { - callback(locationDict); - return; - } - UIView *rootView = viewRegistry[view.rootTag]; - if (rootView == nil) { - callback(locationDict); - return; - } - double locationX = [params[HippyXOnScreenKey] doubleValue]; - double locationY = [params[HippyYOnScreenKey] doubleValue]; - UIView* hitView = [rootView hitTest:{locationX, locationY} withEvent:nil]; - if (hitView != nil && [hitView respondsToSelector:@selector(hippyTag)]) { - [locationDict setObject:hitView.hippyTag forKey:HippyTagKey]; - } - callback(@[locationDict]); - }]; } HIPPY_EXPORT_METHOD(getLocationOnScreen:(nonnull NSNumber *)componentTag