feat:in iOS,use navigationController to navigate
This commit is contained in:
parent
c666c7b81c
commit
f750eb6cae
@ -27,45 +27,33 @@
|
||||
@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)];
|
||||
DoricAsyncResult <NSString *> *result = [DoricJSLoaderManager.instance request:scheme];
|
||||
result.resultCallback = ^(NSString *result) {
|
||||
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];
|
||||
|
||||
});
|
||||
};
|
||||
}
|
||||
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(), ^{
|
||||
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)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 {
|
||||
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)pop:(BOOL)animated {
|
||||
[self.navigationController popViewControllerAnimated:animated];
|
||||
}
|
||||
|
||||
@end
|
||||
|
@ -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
|
@ -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
|
Reference in New Issue
Block a user