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,45 +27,33 @@
@implementation DoricViewController @implementation DoricViewController
- (instancetype)initWithScheme:(NSString *)scheme alias:(NSString *)alias { - (instancetype)initWithScheme:(NSString *)scheme alias:(NSString *)alias {
if (self = [super init]) { if (self = [super init]) {
[self push:scheme alias:alias]; DoricAsyncResult <NSString *> *result = [DoricJSLoaderManager.instance request:scheme];
self.navigationItem.rightBarButtonItem = [[UIBarButtonItem alloc] initWithTitle:@"返回" result.resultCallback = ^(NSString *result) {
style:UIBarButtonItemStylePlain dispatch_async(dispatch_get_main_queue(), ^{
target:self DoricPanel *panel = [DoricPanel new];
action:@selector(pop)]; [panel.view also:^(UIView *it) {
it.backgroundColor = [UIColor whiteColor];
it.width = self.view.width;
it.height = self.view.height - 88;
it.top = 88;
}];
[self.view addSubview:panel.view];
[self addChildViewController:panel];
[panel config:result alias:alias];
});
};
} }
return self; return self;
} }
- (void)push:(NSString *)scheme alias:(NSString *)alias { - (void)push:(NSString *)scheme alias:(NSString *)alias animated:(BOOL)animated {
DoricAsyncResult <NSString *> *result = [DoricJSLoaderManager.instance request:scheme]; DoricViewController *viewController = [[DoricViewController alloc] initWithScheme:scheme alias:alias];
result.resultCallback = ^(NSString *result) { [self.navigationController pushViewController:viewController animated:animated];
dispatch_async(dispatch_get_main_queue(), ^{
DoricPanel *panel = [DoricPanel new];
[panel.view also:^(UIView *it) {
it.backgroundColor = [UIColor whiteColor];
it.width = self.view.width;
it.height = self.view.height - 88;
it.top = 88;
}];
[self.view addSubview:panel.view];
[self addChildViewController:panel];
[panel config:result alias:alias];
});
};
} }
- (void)pop { - (void)pop:(BOOL)animated {
dispatch_async(dispatch_get_main_queue(), ^{ [self.navigationController popViewControllerAnimated:animated];
if (self.childViewControllers.count > 1) {
[self.childViewControllers.lastObject also:^(UIViewController *it) {
[it removeFromParentViewController];
[it.view removeFromSuperview];
}];
} else {
[self.navigationController popViewControllerAnimated:NO];
}
});
} }
@end @end

View File

@ -5,7 +5,7 @@
#import <Foundation/Foundation.h> #import <Foundation/Foundation.h>
@protocol DoricNavigatorProtocol <NSObject> @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 @end

View File

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