feat:move navigator to another class for iOS

This commit is contained in:
pengfei.zhou 2019-11-25 10:50:27 +08:00
parent f750eb6cae
commit 844d44a6f0
8 changed files with 48 additions and 20 deletions

View File

@ -24,3 +24,4 @@
#import "DoricJSLoaderManager.h" #import "DoricJSLoaderManager.h"
#import "DoricNavigatorProtocol.h" #import "DoricNavigatorProtocol.h"
#import "DoricViewController.h" #import "DoricViewController.h"
#import "DoricDefaultNavigator.h"

View File

@ -29,7 +29,7 @@ NS_ASSUME_NONNULL_BEGIN
@class DoricRootNode; @class DoricRootNode;
@interface DoricContext : NSObject @interface DoricContext : NSObject
@property(nonatomic, weak) id <DoricNavigatorProtocol> navigator; @property(nonatomic, strong) id <DoricNavigatorProtocol> navigator;
@property(nonatomic, strong) NSString *contextId; @property(nonatomic, strong) NSString *contextId;
@property(nonatomic, strong) DoricDriver *driver; @property(nonatomic, strong) DoricDriver *driver;
@property(nonatomic, strong) NSMutableDictionary *pluginInstanceMap; @property(nonatomic, strong) NSMutableDictionary *pluginInstanceMap;

View File

@ -24,9 +24,7 @@ @implementation DoricPanel
- (void)config:(NSString *)script alias:(NSString *)alias { - (void)config:(NSString *)script alias:(NSString *)alias {
self.doricContext = [[[DoricContext alloc] initWithScript:script source:alias] also:^(DoricContext *it) { self.doricContext = [[[DoricContext alloc] initWithScript:script source:alias] also:^(DoricContext *it) {
if ([self.parentViewController conformsToProtocol:@protocol(DoricNavigatorProtocol)]) { it.navigator = [[DoricDefaultNavigator alloc] initWithNavigationController:self.navigationController];
it.navigator = (id <DoricNavigatorProtocol>) self.parentViewController;
}
[it.rootNode setupRootView:[[DoricStackView new] also:^(DoricStackView *it) { [it.rootNode setupRootView:[[DoricStackView new] also:^(DoricStackView *it) {
it.width = self.view.width; it.width = self.view.width;
it.height = self.view.height; it.height = self.view.height;

View File

@ -20,6 +20,6 @@
#import <Foundation/Foundation.h> #import <Foundation/Foundation.h>
#import "DoricNavigatorProtocol.h" #import "DoricNavigatorProtocol.h"
@interface DoricViewController : UIViewController <DoricNavigatorProtocol> @interface DoricViewController : UIViewController
- (instancetype)initWithScheme:(NSString *)scheme alias:(NSString *)alias; - (instancetype)initWithScheme:(NSString *)scheme alias:(NSString *)alias;
@end @end

View File

@ -46,14 +46,4 @@ - (instancetype)initWithScheme:(NSString *)scheme alias:(NSString *)alias {
} }
return self; 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 @end

View File

@ -0,0 +1,10 @@
//
// Created by pengfei.zhou on 2019/11/25.
//
#import <Foundation/Foundation.h>
#import "DoricNavigatorProtocol.h"
@interface DoricDefaultNavigator : NSObject <DoricNavigatorProtocol>
- (instancetype)initWithNavigationController:(UINavigationController *)navigationController;
@end

View File

@ -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

View File

@ -170,13 +170,13 @@ export function storage(context: BridgeContext) {
export function navigator(context: BridgeContext) { export function navigator(context: BridgeContext) {
return { return {
push: (scheme: string, alias: string) => { push: (scheme: string, alias: string, animated = true) => {
return context.navigator.push({ return context.navigator.push({
scheme, alias scheme, alias, animated
}) })
}, },
pop: () => { pop: (animated = true) => {
return context.navigator.pop() return context.navigator.pop({ animated })
}, },
} }
} }