iOS: add navigation search for launch dev mode vc
This commit is contained in:
parent
bebd1c6fe9
commit
28713aebbd
@ -45,6 +45,8 @@ NS_ASSUME_NONNULL_BEGIN
|
||||
|
||||
- (void)openDevMode;
|
||||
|
||||
- (void)openDevMode:(UIViewController *)vc;
|
||||
|
||||
- (void)closeDevMode;
|
||||
|
||||
- (BOOL)isInDevMode;
|
||||
@ -72,6 +74,9 @@ NS_ASSUME_NONNULL_BEGIN
|
||||
- (void)addStatusCallback:(id <DoricDevStatusCallback>)callback;
|
||||
|
||||
- (void)removeStatusCallback:(id <DoricDevStatusCallback>)callback;
|
||||
|
||||
UIViewController* _Nonnull findBestViewController(UIViewController* _Nonnull vc);
|
||||
|
||||
@end
|
||||
|
||||
NS_ASSUME_NONNULL_END
|
||||
|
@ -27,6 +27,7 @@
|
||||
#import "DoricDebugDriver.h"
|
||||
#import "DoricDevViewController.h"
|
||||
#import "DoricDevMonitor.h"
|
||||
#import "DoricUtil.h"
|
||||
|
||||
@interface DoricContextDebuggable : NSObject
|
||||
@property(nonatomic, weak) DoricContext *doricContext;
|
||||
@ -104,6 +105,19 @@ - (void)openDevMode {
|
||||
[navigationController pushViewController:devViewController animated:NO];
|
||||
}
|
||||
|
||||
- (void)openDevMode:(UIViewController *)vc {
|
||||
DoricDevViewController *devViewController = [DoricDevViewController new];
|
||||
|
||||
UIViewController *viewController = findBestViewController(vc);
|
||||
UINavigationController *navigationController;
|
||||
if ([viewController isKindOfClass:[UINavigationController class]]) {
|
||||
navigationController = (UINavigationController *) viewController;
|
||||
} else {
|
||||
navigationController = viewController.navigationController;
|
||||
}
|
||||
[navigationController pushViewController:devViewController animated:NO];
|
||||
}
|
||||
|
||||
- (void)closeDevMode {
|
||||
[self stopDebugging:YES];
|
||||
if (self.wsClient) {
|
||||
@ -259,4 +273,36 @@ - (NSString *)ip {
|
||||
stringByReplacingOccurrencesOfString:@":7777"
|
||||
withString:@""];
|
||||
}
|
||||
|
||||
UIViewController* _Nonnull findBestViewController(UIViewController* _Nonnull vc) {
|
||||
if (vc.presentedViewController && ![vc.presentedViewController isKindOfClass:[UIAlertController class]]) {
|
||||
// Return presented view controller
|
||||
return findBestViewController(vc.presentedViewController);
|
||||
} else if ([vc isKindOfClass:[UISplitViewController class]]) {
|
||||
// Return right hand side
|
||||
UISplitViewController* svc = (UISplitViewController*) vc;
|
||||
if (svc.viewControllers.count > 0)
|
||||
return findBestViewController(svc.viewControllers.lastObject);
|
||||
else
|
||||
return vc;
|
||||
} else if ([vc isKindOfClass:[UINavigationController class]]) {
|
||||
// Return top view
|
||||
UINavigationController* svc = (UINavigationController*) vc;
|
||||
if (svc.viewControllers.count > 0)
|
||||
return findBestViewController(svc.topViewController);
|
||||
else
|
||||
return vc;
|
||||
} else if ([vc isKindOfClass:[UITabBarController class]]) {
|
||||
// Return visible view
|
||||
UITabBarController* svc = (UITabBarController*) vc;
|
||||
if (svc.viewControllers.count > 0)
|
||||
return findBestViewController(svc.selectedViewController);
|
||||
else
|
||||
return vc;
|
||||
} else {
|
||||
// Unknown view controller type, return last child view controller
|
||||
return vc;
|
||||
}
|
||||
}
|
||||
|
||||
@end
|
||||
|
@ -69,7 +69,7 @@ - (BOOL)isSimulator {
|
||||
|
||||
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
|
||||
if (indexPath.row == 0) {
|
||||
[[DoricDev instance] openDevMode];
|
||||
[[DoricDev instance] openDevMode:self];
|
||||
return;
|
||||
}
|
||||
NSString *file = self.demoFilePaths[(NSUInteger) indexPath.row];
|
||||
|
Reference in New Issue
Block a user