feat: enhance plugin navigator,add popSelf and popToRoot

This commit is contained in:
pengfei.zhou
2021-06-08 11:55:21 +08:00
committed by osborn
parent 864ffa0de7
commit 4da1f3be9d
15 changed files with 162 additions and 8 deletions

View File

@@ -26,6 +26,10 @@ extern NSString *const DORIC_MASK_RETRY;
@interface DoricViewController : UIViewController <DoricNavigatorDelegate, DoricNavBarDelegate>
@property(nonatomic, copy) NSString *source;
@property(nonatomic, copy) NSString *alias;
@property(nonatomic, copy) NSString *extra;
@property(nonatomic, strong) DoricPanel *doricPanel;
@property(nonatomic) BOOL statusBarHidden;
@property(nonatomic) int statusBarMode;

View File

@@ -29,9 +29,6 @@ @interface DoricViewController ()
@property(nonatomic) BOOL navBarHidden;
@property(nonatomic, strong) UIImage *navBarImage;
@property(nonatomic, strong) UIView *maskView;
@property(nonatomic, copy) NSString *source;
@property(nonatomic, copy) NSString *alias;
@property(nonatomic, copy) NSString *extra;
@end
@implementation DoricViewController
@@ -105,9 +102,33 @@ - (void)doric_navigator_push:(NSString *)source alias:(NSString *)alias animated
}
- (void)doric_navigator_pop:(BOOL)animated {
[self.navigationController popViewControllerAnimated:animated];
if (self.presentingViewController) {
[self dismissViewControllerAnimated:animated completion:nil];
} else {
[self.navigationController popViewControllerAnimated:animated];
}
}
- (void)doric_navigator_popSelf:(BOOL)animated {
if (self.presentingViewController) {
[self dismissViewControllerAnimated:animated completion:nil];
} else {
NSMutableArray *tempStack = [self.navigationController.viewControllers mutableCopy];
for (UIViewController *vc in self.navigationController.viewControllers) {
if (vc == self) {
[tempStack removeObject:vc];
break;
}
}
[self.navigationController setViewControllers:[tempStack copy] animated:animated];
}
}
- (void)doric_navigator_popToRoot:(BOOL)animated {
[self.navigationController popToRootViewControllerAnimated:animated];
}
- (BOOL)doric_navBar_isHidden {
return self.navigationController.navigationBarHidden;
}

View File

@@ -23,4 +23,8 @@
- (void)doric_navigator_push:(NSString *)source alias:(NSString *)alias animated:(BOOL)animated extra:(NSString *)extra;
- (void)doric_navigator_pop:(BOOL)animated;
- (void)doric_navigator_popSelf:(BOOL)animated;
- (void)doric_navigator_popToRoot:(BOOL)animated;
@end

View File

@@ -22,7 +22,7 @@
#import "DoricExtensions.h"
@implementation DoricNavigatorPlugin
- (void)push:(NSDictionary *)params {
- (void)push:(NSDictionary *)params withPromise:(DoricPromise *)promise {
__weak typeof(self) _self = self;
[self.doricContext dispatchToMainQueue:^{
__strong typeof(_self) self = _self;
@@ -35,15 +35,37 @@ - (void)push:(NSDictionary *)params {
alias = [config optString:@"alias" defaultValue:source];
}
[self.doricContext.navigator doric_navigator_push:source alias:alias animated:animated extra:config[@"extra"]];
[promise resolve:nil];
}];
}
- (void)pop:(NSDictionary *)params {
- (void)pop:(NSDictionary *)params withPromise:(DoricPromise *)promise {
__weak typeof(self) _self = self;
[self.doricContext dispatchToMainQueue:^{
__strong typeof(_self) self = _self;
BOOL animated = [params optBool:@"animated" defaultValue:YES];
[self.doricContext.navigator doric_navigator_pop:animated];
[promise resolve:nil];
}];
}
- (void)popSelf:(NSDictionary *)params withPromise:(DoricPromise *)promise {
__weak typeof(self) _self = self;
[self.doricContext dispatchToMainQueue:^{
__strong typeof(_self) self = _self;
BOOL animated = [params optBool:@"animated" defaultValue:YES];
[self.doricContext.navigator doric_navigator_popSelf:animated];
[promise resolve:nil];
}];
}
- (void)popToRoot:(NSDictionary *)params withPromise:(DoricPromise *)promise {
__weak typeof(self) _self = self;
[self.doricContext dispatchToMainQueue:^{
__strong typeof(_self) self = _self;
BOOL animated = [params optBool:@"animated" defaultValue:YES];
[self.doricContext.navigator doric_navigator_popToRoot:animated];
[promise resolve:nil];
}];
}