feat:move navigator to another class for iOS
This commit is contained in:
parent
f750eb6cae
commit
844d44a6f0
@ -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"
|
@ -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;
|
||||||
|
@ -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;
|
||||||
|
@ -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
|
@ -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
|
||||||
|
10
iOS/Pod/Classes/Navigator/DoricDefaultNavigator.h
Normal file
10
iOS/Pod/Classes/Navigator/DoricDefaultNavigator.h
Normal 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
|
29
iOS/Pod/Classes/Navigator/DoricDefaultNavigator.m
Normal file
29
iOS/Pod/Classes/Navigator/DoricDefaultNavigator.m
Normal 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
|
@ -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 })
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
}
|
}
|
Reference in New Issue
Block a user