Skip to content

Commit

Permalink
[feat]iOS适配ReactNative框架,补全操作指令生成逻辑。
Browse files Browse the repository at this point in the history
  • Loading branch information
Hulk committed Feb 27, 2025
1 parent 97e2981 commit bbed112
Showing 1 changed file with 46 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
#import <DiDiPrism/PrismCellInstructionGenerator.h>
#import <DiDiPrism/PrismViewControllerInstructionGenerator.h>
#import <DiDiPrism/PrismTextFieldInstructionGenerator.h>
#import <DiDiPrism/PrismRNViewInstructionGenerator.h>

@implementation PrismBehaviorRecordManager (PrismDispatchListenerProtocol)
#pragma mark -delegate
Expand Down Expand Up @@ -92,6 +93,51 @@ - (void)dispatchEvent:(PrismDispatchEvent)event withSender:(NSObject *)sender pa
[self addInstruction:instruction withEventParams:eventParams];
}
}
else if (event == PrismDispatchEventRCTSurfaceTouchHandlerSetState) {
UIGestureRecognizer *gestureRecognizer = (UIGestureRecognizer *)sender;
if ([gestureRecognizer isKindOfClass:NSClassFromString(@"RCTSurfaceTouchHandler")]) {
UIView *view = gestureRecognizer.view;
NSObject *surface = nil;
if ([view respondsToSelector:@selector(surface)]) {
surface = [view performSelector:@selector(surface)];
}
NSObject *properties = nil;
if (surface && [surface respondsToSelector:@selector(properties)]) {
properties = [surface performSelector:@selector(properties)];
}
NSString *pageInfo = nil;
if (properties && [properties isKindOfClass:[NSDictionary class]]) {
pageInfo = [(NSDictionary*)properties prism_stringForKey:@"drnPage"];
}

CGPoint viewPoint = [gestureRecognizer locationInView:view];
// 背景是曾经遇到过研发自行重写了hitTest:withEvent:方法,并且存在不符合官方建议的定制逻辑。
// 导致我们在主动调用hitTest:withEvent:方法时,触发了不必要的业务逻辑,导致非预期的问题。(官方是允许主动调用这个方法的)
// RN支撑的前端代码不会对hitTest:withEvent:有特殊业务定制,所以可放心调用。
UIView *hitView = [view hitTest:viewPoint withEvent:nil];

// hitView为RCTImageComponentView大概率获取不到有效信息
// 两种情况:
// 一种是确实是有效按钮,比如后退按钮,需要交换RN框架已有实现来取得图片信息。
// 一种是可能为一个占位符,非有效图片,需要遍历其superview找有效内容。
if ([hitView isKindOfClass:NSClassFromString(@"RCTImageComponentView")]) {
while ([hitView superview] &&
[[hitView superview] isKindOfClass:NSClassFromString(@"RCTViewComponentView")]) {
hitView = [hitView superview];
if ([hitView isMemberOfClass:NSClassFromString(@"RCTViewComponentView")]) {
break;
}
}
}

PrismInstructionModel *instructionModel = [PrismRNViewInstructionGenerator getInstructionModelOfView:hitView withPageInfo:pageInfo];
NSString *instruction = [instructionModel toString];
if (instruction.length) {
NSDictionary *eventParams = [PrismInstructionParamUtil getEventParamsWithElement:hitView];
[self addInstruction:instruction withEventParams:eventParams];
}
}
}
else if (event == PrismDispatchEventUILongPressGestureRecognizerAction) {
UILongPressGestureRecognizer *longPressGesture = (UILongPressGestureRecognizer*)sender;
PrismInstructionModel *instructionModel = [PrismLongPressGestureInstructionGenerator getInstructionModelOfLongPressGesture:longPressGesture];
Expand Down

0 comments on commit bbed112

Please sign in to comment.