diff --git a/iOS/Pod/Classes/Doric.h b/iOS/Pod/Classes/Doric.h index 9df6d257..ef285e59 100644 --- a/iOS/Pod/Classes/Doric.h +++ b/iOS/Pod/Classes/Doric.h @@ -23,4 +23,5 @@ #import "DoricPanel.h" #import "DoricJSLoaderManager.h" #import "DoricNavigatorProtocol.h" -#import "DoricViewController.h" \ No newline at end of file +#import "DoricViewController.h" +#import "DoricDefaultNavigator.h" \ No newline at end of file diff --git a/iOS/Pod/Classes/DoricContext.h b/iOS/Pod/Classes/DoricContext.h index 7c1bcefd..e511ab77 100644 --- a/iOS/Pod/Classes/DoricContext.h +++ b/iOS/Pod/Classes/DoricContext.h @@ -29,7 +29,7 @@ NS_ASSUME_NONNULL_BEGIN @class DoricRootNode; @interface DoricContext : NSObject -@property(nonatomic, weak) id navigator; +@property(nonatomic, strong) id navigator; @property(nonatomic, strong) NSString *contextId; @property(nonatomic, strong) DoricDriver *driver; @property(nonatomic, strong) NSMutableDictionary *pluginInstanceMap; diff --git a/iOS/Pod/Classes/DoricPanel.m b/iOS/Pod/Classes/DoricPanel.m index b4cc5af1..9eadcce8 100644 --- a/iOS/Pod/Classes/DoricPanel.m +++ b/iOS/Pod/Classes/DoricPanel.m @@ -24,9 +24,7 @@ @implementation DoricPanel - (void)config:(NSString *)script alias:(NSString *)alias { self.doricContext = [[[DoricContext alloc] initWithScript:script source:alias] also:^(DoricContext *it) { - if ([self.parentViewController conformsToProtocol:@protocol(DoricNavigatorProtocol)]) { - it.navigator = (id ) self.parentViewController; - } + it.navigator = [[DoricDefaultNavigator alloc] initWithNavigationController:self.navigationController]; [it.rootNode setupRootView:[[DoricStackView new] also:^(DoricStackView *it) { it.width = self.view.width; it.height = self.view.height; diff --git a/iOS/Pod/Classes/DoricViewController.h b/iOS/Pod/Classes/DoricViewController.h index b39c3e4a..590dc5fd 100644 --- a/iOS/Pod/Classes/DoricViewController.h +++ b/iOS/Pod/Classes/DoricViewController.h @@ -20,6 +20,6 @@ #import #import "DoricNavigatorProtocol.h" -@interface DoricViewController : UIViewController +@interface DoricViewController : UIViewController - (instancetype)initWithScheme:(NSString *)scheme alias:(NSString *)alias; @end \ No newline at end of file diff --git a/iOS/Pod/Classes/DoricViewController.m b/iOS/Pod/Classes/DoricViewController.m index 5627c989..bfbadd7e 100644 --- a/iOS/Pod/Classes/DoricViewController.m +++ b/iOS/Pod/Classes/DoricViewController.m @@ -46,14 +46,4 @@ - (instancetype)initWithScheme:(NSString *)scheme alias:(NSString *)alias { } return self; } - -- (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 diff --git a/iOS/Pod/Classes/Navigator/DoricDefaultNavigator.h b/iOS/Pod/Classes/Navigator/DoricDefaultNavigator.h new file mode 100644 index 00000000..d185bb66 --- /dev/null +++ b/iOS/Pod/Classes/Navigator/DoricDefaultNavigator.h @@ -0,0 +1,10 @@ +// +// Created by pengfei.zhou on 2019/11/25. +// + +#import +#import "DoricNavigatorProtocol.h" + +@interface DoricDefaultNavigator : NSObject +- (instancetype)initWithNavigationController:(UINavigationController *)navigationController; +@end \ No newline at end of file diff --git a/iOS/Pod/Classes/Navigator/DoricDefaultNavigator.m b/iOS/Pod/Classes/Navigator/DoricDefaultNavigator.m new file mode 100644 index 00000000..b1945f31 --- /dev/null +++ b/iOS/Pod/Classes/Navigator/DoricDefaultNavigator.m @@ -0,0 +1,29 @@ +// +// Created by pengfei.zhou on 2019/11/25. +// + +#import "DoricDefaultNavigator.h" +#import "DoricViewController.h" + +@interface DoricDefaultNavigator () +@property(nonatomic, weak) UINavigationController *navigationController; +@end + +@implementation DoricDefaultNavigator +- (instancetype)initWithNavigationController:(UINavigationController *)navigationController { + if (self = [super init]) { + _navigationController = navigationController; + } + return self; +} + +- (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 \ No newline at end of file diff --git a/js-framework/src/util/nativeModules.ts b/js-framework/src/util/nativeModules.ts index d46ced99..1dd8f850 100644 --- a/js-framework/src/util/nativeModules.ts +++ b/js-framework/src/util/nativeModules.ts @@ -170,13 +170,13 @@ export function storage(context: BridgeContext) { export function navigator(context: BridgeContext) { return { - push: (scheme: string, alias: string) => { + push: (scheme: string, alias: string, animated = true) => { return context.navigator.push({ - scheme, alias + scheme, alias, animated }) }, - pop: () => { - return context.navigator.pop() + pop: (animated = true) => { + return context.navigator.pop({ animated }) }, } } \ No newline at end of file