Skip to content

Commit

Permalink
fix(devtools): mapping between DOM tree and UI inspector (#4141)
Browse files Browse the repository at this point in the history
* 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
  • Loading branch information
Cyunong authored and wwwcg committed Dec 11, 2024
1 parent 719008e commit 4d8ba71
Showing 1 changed file with 22 additions and 21 deletions.
43 changes: 22 additions & 21 deletions renderer/native/ios/renderer/component/view/HippyViewManager.mm
Original file line number Diff line number Diff line change
Expand Up @@ -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<NSNumber *, UIView *> *viewRegistry) {
NSMutableDictionary *locationDict = [NSMutableDictionary dictionaryWithDictionary:@{
HippyTagKey: @(InvalidTag),
[self.bridge.uiManager addUIBlock:^(__unused HippyUIManager *uiManager, NSDictionary<NSNumber *, UIView *> *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
Expand Down

0 comments on commit 4d8ba71

Please sign in to comment.