From 1273a72f22c82bc90bd769ae29986f3c111f7059 Mon Sep 17 00:00:00 2001 From: arnonchen <52275454+Cyunong@users.noreply.github.com> Date: Mon, 2 Dec 2024 14:15:33 +0800 Subject: [PATCH] fix(devtools): mapping between DOM tree and UI inspector (#4141) * fix(devtools): fix the mapping between DOM tree and UI inspector * fix(devtools): fix potential crash * fix(devtools): fix magic number * fix(devtools): fix the name of function * fix(ios): fix null hippy tag in UI inspector * fix(ios): todo not a hippy view * fix(ios): simplify logic * fix(ios): simplify logic and refine todo * fix(ios): fix indent error --- .../component/view/HippyViewManager.mm | 43 ++++++++++--------- 1 file changed, 22 insertions(+), 21 deletions(-) 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