Skip to content

Commit

Permalink
fix: 后退手势的支持漏洞。
Browse files Browse the repository at this point in the history
  • Loading branch information
Hulk committed Dec 21, 2020
1 parent 5042a8e commit 6686b9f
Show file tree
Hide file tree
Showing 5 changed files with 20 additions and 18 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -31,14 +31,7 @@ + (NSString*)getInstructionOfEdgePanGesture:(UIScreenEdgePanGestureRecognizer*)e
}

NSString *responseChainInfo = [PrismInstructionResponseChainUtil getResponseChainInfoWithElement:view];
// 获取响应链的方法本身有个问题,就是如果self.view为viewController.view的话,并不会统计到这个viewController。
// 但是这一点对于后退滑动手势来说必须修复,所以先在这里修复。其他地方目前运行良好就不做改动(只是回放遍历的时候要多遍历一些)
UIViewController *lastViewController = nil;
UIResponder* nextResponder = [view nextResponder];
if ([nextResponder isKindOfClass:[UIViewController class]]) {
lastViewController = (UIViewController*)nextResponder;
}
view.autoDotFinalMark = [NSString stringWithFormat:@"%@%@%@%@", kBeginOfViewMotionFlag, kViewMotionEdgePanGestureFlag, responseChainInfo, lastViewController ? NSStringFromClass([lastViewController class]) : @""];
view.autoDotFinalMark = [NSString stringWithFormat:@"%@%@%@", kBeginOfViewMotionFlag, kViewMotionEdgePanGestureFlag, responseChainInfo];
return view.autoDotFinalMark;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,12 +25,7 @@ - (UIResponder*)searchRootResponderWithClassName:(NSString*)className {
[[keyWindow subviews] enumerateObjectsUsingBlock:^(__kindof UIView * _Nonnull obj, NSUInteger idx, BOOL * _Nonnull stop) {
if ([obj isKindOfClass:NSClassFromString(@"UITransitionView")] && [[obj subviews] count]) {
UIView *aimView = (UIView*)[obj subviews][0];
if ([[aimView nextResponder] isKindOfClass:[UIViewController class]]) {
presentedVC = (UIViewController*)[aimView nextResponder];
}
else {
presentedVC = [((UIView*)[obj subviews][0]) prism_viewController];
}
presentedVC = [[aimView nextResponder] isKindOfClass:[UIViewController class]] ? (UIViewController*)[aimView nextResponder] : [aimView prism_viewController];
*stop = YES;
}
}];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
// Category
#import "PrismBaseInstructionParser+Protected.h"
#import "NSArray+PrismExtends.h"
#import "UIView+PrismExtends.h"

@interface PrismEdgePanGestureInstructionParser()

Expand All @@ -25,6 +26,9 @@ - (PrismInstructionParseResult)parseWithFormatter:(PrismInstructionFormatter *)f
if (!responder) {
return PrismInstructionParseResultFail;
}
if (!viewPathArray.lastObject.length) {
viewPathArray = [viewPathArray subarrayWithRange:NSMakeRange(0, viewPathArray.count - 1)];
}
NSInteger index = 2;
for (; index < viewPathArray.count; index++) {
Class class = NSClassFromString(viewPathArray[index]);
Expand All @@ -41,11 +45,21 @@ - (PrismInstructionParseResult)parseWithFormatter:(PrismInstructionFormatter *)f
return PrismInstructionParseResultError;
}

UIViewController *targetViewController = (UIViewController*)responder;
UIViewController *targetViewController = nil;
if ([responder isKindOfClass:[UIView class]]) {
UIView *view = (UIView*)responder;
targetViewController = [[view nextResponder] isKindOfClass:[UIViewController class]] ? (UIViewController*)[view nextResponder] : [view prism_viewController];
}
else {
targetViewController = (UIViewController*)responder;
}
UIView *targetView = targetViewController.view;
UIScreenEdgePanGestureRecognizer *edgePanGesture = [self searchEdgePanGestureFromSuperView:targetView];
if (edgePanGesture) {
if (targetViewController.navigationController) {
if ([targetViewController isKindOfClass:[UINavigationController class]]) {
[(UINavigationController*)targetViewController popViewControllerAnimated:YES];
}
else if (targetViewController.navigationController) {
[targetViewController.navigationController popViewControllerAnimated:YES];
}
else if (targetViewController.parentViewController.presentingViewController) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ + (NSString*)getResponseChainInfoWithElement:(UIView*)element {
#pragma mark - private method
+ (NSArray<UIViewController*>*)getParentViewControllersOfView:(UIView*)view {
NSMutableArray<UIViewController*> *viewControllers = [NSMutableArray array];
UIViewController *viewController = view.prism_viewController;
UIViewController *viewController = [view prism_viewController];
if (viewController) {
[viewControllers addObject:viewController];
while (viewController.parentViewController) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ - (void)autoDot_edgePanAction:(UIScreenEdgePanGestureRecognizer*)edgePanGestureR
}

if (edgePanGestureRecognizer.state == UIGestureRecognizerStateBegan) {
UIViewController *viewController = self.view.prism_viewController;
UIViewController *viewController = [[self.view nextResponder] isKindOfClass:[UIViewController class]] ? (UIViewController*)[self.view nextResponder] : [self.view prism_viewController];
UINavigationController *navigationController = [viewController isKindOfClass:[UINavigationController class]] ? (UINavigationController*)viewController : viewController.navigationController;
[self setAutoDotNavigationController:navigationController];
NSInteger viewControllerCount = navigationController.viewControllers.count;
Expand Down

0 comments on commit 6686b9f

Please sign in to comment.