feat:in iOS,use navigationController to navigate

This commit is contained in:
pengfei.zhou 2019-11-25 10:21:37 +08:00
parent c666c7b81c
commit f750eb6cae
3 changed files with 38 additions and 38 deletions

View File

@ -27,16 +27,6 @@
@implementation DoricViewController
- (instancetype)initWithScheme:(NSString *)scheme alias:(NSString *)alias {
if (self = [super init]) {
[self push:scheme alias:alias];
self.navigationItem.rightBarButtonItem = [[UIBarButtonItem alloc] initWithTitle:@"返回"
style:UIBarButtonItemStylePlain
target:self
action:@selector(pop)];
}
return self;
}
- (void)push:(NSString *)scheme alias:(NSString *)alias {
DoricAsyncResult <NSString *> *result = [DoricJSLoaderManager.instance request:scheme];
result.resultCallback = ^(NSString *result) {
dispatch_async(dispatch_get_main_queue(), ^{
@ -50,22 +40,20 @@ - (void)push:(NSString *)scheme alias:(NSString *)alias {
[self.view addSubview:panel.view];
[self addChildViewController:panel];
[panel config:result alias:alias];
});
};
}
return self;
}
- (void)pop {
dispatch_async(dispatch_get_main_queue(), ^{
if (self.childViewControllers.count > 1) {
[self.childViewControllers.lastObject also:^(UIViewController *it) {
[it removeFromParentViewController];
[it.view removeFromSuperview];
}];
} else {
[self.navigationController popViewControllerAnimated:NO];
}
- (void)push:(NSString *)scheme alias:(NSString *)alias animated:(BOOL)animated {
DoricViewController *viewController = [[DoricViewController alloc] initWithScheme:scheme alias:alias];
[self.navigationController pushViewController:viewController animated:animated];
}
});
- (void)pop:(BOOL)animated {
[self.navigationController popViewControllerAnimated:animated];
}
@end

View File

@ -5,7 +5,7 @@
#import <Foundation/Foundation.h>
@protocol DoricNavigatorProtocol <NSObject>
- (void)push:(NSString *)scheme alias:(NSString *)alias;
- (void)push:(NSString *)scheme alias:(NSString *)alias animated:(BOOL)animated;
- (void)pop;
- (void)pop:(BOOL)animated;
@end

View File

@ -22,10 +22,22 @@
@implementation DoricNavigatorPlugin
- (void)push:(NSDictionary *)params {
[self.doricContext.navigator push:params[@"scheme"] alias:params[@"alias"]];
dispatch_async(dispatch_get_main_queue(), ^{
BOOL animated = YES;
if (params[@"animated"]) {
animated = [params[@"animated"] boolValue];
}
[self.doricContext.navigator push:params[@"scheme"] alias:params[@"alias"] animated:animated];
});
}
- (void)pop {
[self.doricContext.navigator pop];
- (void)pop:(NSDictionary *)params {
dispatch_async(dispatch_get_main_queue(), ^{
BOOL animated = YES;
if (params[@"animated"]) {
animated = [params[@"animated"] boolValue];
}
[self.doricContext.navigator pop:animated];
});
}
@end