From bf7a22a4d7e7f418451163497ab6db5f929669a5 Mon Sep 17 00:00:00 2001 From: "pengfei.zhou" Date: Mon, 9 Dec 2019 20:32:33 +0800 Subject: [PATCH] feat:Navigator add extra --- Example/Example/DemoVC.m | 2 +- Example/Example/ViewController.m | 4 +++- Pod/Classes/DoricContext.h | 3 ++- Pod/Classes/DoricContext.m | 5 +++-- Pod/Classes/DoricPanel.h | 2 +- Pod/Classes/DoricPanel.m | 4 ++-- Pod/Classes/DoricViewController.h | 6 +++--- Pod/Classes/DoricViewController.m | 8 ++++---- Pod/Classes/Navigator/DoricNavigatorDelegate.h | 2 +- Pod/Classes/Plugin/DoricNavigatorPlugin.m | 15 ++++++++++++--- 10 files changed, 32 insertions(+), 19 deletions(-) diff --git a/Example/Example/DemoVC.m b/Example/Example/DemoVC.m index bc3e8b9e..82d7e40a 100644 --- a/Example/Example/DemoVC.m +++ b/Example/Example/DemoVC.m @@ -33,7 +33,7 @@ - (void)viewDidLoad { [self.view addSubview:it]; }]; [self addChildViewController:panel]; - [panel config:jsContent alias:self.filePath]; + [panel config:jsContent alias:self.filePath extra:nil]; } @end diff --git a/Example/Example/ViewController.m b/Example/Example/ViewController.m index 59a11e8a..f2a2a583 100644 --- a/Example/Example/ViewController.m +++ b/Example/Example/ViewController.m @@ -77,7 +77,9 @@ - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath if ([file containsString:@"NavigatorDemo"]) { DoricViewController *doricViewController = [[DoricViewController alloc] initWithScheme:[NSString stringWithFormat:@"assets://demo/%@", file] - alias:self.demoFilePaths[(NSUInteger) indexPath.row]]; + alias:self.demoFilePaths[(NSUInteger) indexPath.row] + extra:nil + ]; [self.navigationController pushViewController:doricViewController animated:NO]; } else { DemoVC *demoVC = [[DemoVC alloc] initWithPath:file]; diff --git a/Pod/Classes/DoricContext.h b/Pod/Classes/DoricContext.h index b0bf324f..f919c7cf 100644 --- a/Pod/Classes/DoricContext.h +++ b/Pod/Classes/DoricContext.h @@ -41,8 +41,9 @@ NS_ASSUME_NONNULL_BEGIN @property(nonatomic, strong) NSMutableDictionary *initialParams; @property(nonatomic, strong) DoricRootNode *rootNode; @property(nonatomic, strong) NSMutableDictionary *headNodes; +@property(nonatomic, copy) NSString *extra; -- (instancetype)initWithScript:(NSString *)script source:(NSString *)source; +- (instancetype)initWithScript:(NSString *)script source:(NSString *)source extra:(NSString *)extra; - (DoricAsyncResult *)callEntity:(NSString *)method, ...; diff --git a/Pod/Classes/DoricContext.m b/Pod/Classes/DoricContext.m index 27fc76e7..7e9815ce 100644 --- a/Pod/Classes/DoricContext.m +++ b/Pod/Classes/DoricContext.m @@ -28,7 +28,7 @@ @implementation DoricContext -- (instancetype)initWithScript:(NSString *)script source:(NSString *)source { +- (instancetype)initWithScript:(NSString *)script source:(NSString *)source extra:(NSString *)extra { if (self = [super init]) { _driver = [DoricDriver instance]; _pluginInstanceMap = [NSMutableDictionary new]; @@ -39,6 +39,7 @@ - (instancetype)initWithScript:(NSString *)script source:(NSString *)source { _script = script; _source = source; _initialParams = [@{@"width": @(0), @"height": @(0)} mutableCopy]; + _extra = extra; [self callEntity:DORIC_ENTITY_CREATE, nil]; } return self; @@ -78,7 +79,7 @@ - (void)initContextWithWidth:(CGFloat)width height:(CGFloat)height { it[@"width"] = @(width); it[@"height"] = @(height); }]; - [self callEntity:DORIC_ENTITY_INIT, self.initialParams, nil]; + [self callEntity:DORIC_ENTITY_INIT, self.initialParams, self.extra, nil]; } - (void)reload:(NSString *)script { diff --git a/Pod/Classes/DoricPanel.h b/Pod/Classes/DoricPanel.h index 56682d32..4dedaf8f 100644 --- a/Pod/Classes/DoricPanel.h +++ b/Pod/Classes/DoricPanel.h @@ -25,5 +25,5 @@ @interface DoricPanel : UIViewController @property(nonatomic, strong) DoricContext *doricContext; -- (void)config:(NSString *)script alias:(NSString *)alias; +- (void)config:(NSString *)script alias:(NSString *)alias extra:(NSString *)extra; @end \ No newline at end of file diff --git a/Pod/Classes/DoricPanel.m b/Pod/Classes/DoricPanel.m index a1cf9117..fb8463eb 100644 --- a/Pod/Classes/DoricPanel.m +++ b/Pod/Classes/DoricPanel.m @@ -22,8 +22,8 @@ @implementation DoricPanel -- (void)config:(NSString *)script alias:(NSString *)alias { - self.doricContext = [[[DoricContext alloc] initWithScript:script source:alias] also:^(DoricContext *it) { +- (void)config:(NSString *)script alias:(NSString *)alias extra:(NSString *)extra { + self.doricContext = [[[DoricContext alloc] initWithScript:script source:alias extra:extra] also:^(DoricContext *it) { [it.rootNode setupRootView:[[DoricStackView new] also:^(DoricStackView *it) { [self.view addSubview:it]; }]]; diff --git a/Pod/Classes/DoricViewController.h b/Pod/Classes/DoricViewController.h index 99037937..c4c7eb5e 100644 --- a/Pod/Classes/DoricViewController.h +++ b/Pod/Classes/DoricViewController.h @@ -8,7 +8,7 @@ * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, + * distributed under the License is distributed onO an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. @@ -22,5 +22,5 @@ #import "DoricNavBarDelegate.h" @interface DoricViewController : UIViewController -- (instancetype)initWithScheme:(NSString *)scheme alias:(NSString *)alias; -@end \ No newline at end of file +- (instancetype)initWithScheme:(NSString *)scheme alias:(NSString *)alias extra:(NSString *)extra; +@end diff --git a/Pod/Classes/DoricViewController.m b/Pod/Classes/DoricViewController.m index b20bb3c8..18d05bfa 100644 --- a/Pod/Classes/DoricViewController.m +++ b/Pod/Classes/DoricViewController.m @@ -32,7 +32,7 @@ @interface DoricViewController () @end @implementation DoricViewController -- (instancetype)initWithScheme:(NSString *)scheme alias:(NSString *)alias { +- (instancetype)initWithScheme:(NSString *)scheme alias:(NSString *)alias extra:(NSString *)extra { if (self = [super init]) { self.edgesForExtendedLayout = UIRectEdgeNone; DoricAsyncResult *result = [DoricJSLoaderManager.instance request:scheme]; @@ -46,7 +46,7 @@ - (instancetype)initWithScheme:(NSString *)scheme alias:(NSString *)alias { }]; [self.view addSubview:panel.view]; [self addChildViewController:panel]; - [panel config:result alias:alias]; + [panel config:result alias:alias extra:extra]; panel.doricContext.navigator = self; panel.doricContext.navBar = self; self.doricPanel = panel; @@ -78,8 +78,8 @@ - (void)viewWillLayoutSubviews { self.doricPanel.view.height = self.view.height; } -- (void)doric_navigator_push:(NSString *)scheme alias:(NSString *)alias animated:(BOOL)animated { - DoricViewController *viewController = [[DoricViewController alloc] initWithScheme:scheme alias:alias]; +- (void)doric_navigator_push:(NSString *)scheme alias:(NSString *)alias animated:(BOOL)animated extra:(NSString *)extra { + DoricViewController *viewController = [[DoricViewController alloc] initWithScheme:scheme alias:alias extra:extra]; [self.navigationController pushViewController:viewController animated:animated]; } diff --git a/Pod/Classes/Navigator/DoricNavigatorDelegate.h b/Pod/Classes/Navigator/DoricNavigatorDelegate.h index 93f23eb8..aafc8c6a 100644 --- a/Pod/Classes/Navigator/DoricNavigatorDelegate.h +++ b/Pod/Classes/Navigator/DoricNavigatorDelegate.h @@ -20,7 +20,7 @@ #import @protocol DoricNavigatorDelegate -- (void)doric_navigator_push:(NSString *)scheme alias:(NSString *)alias animated:(BOOL)animated; +- (void)doric_navigator_push:(NSString *)scheme alias:(NSString *)alias animated:(BOOL)animated extra:(NSString *)extra; - (void)doric_navigator_pop:(BOOL)animated; @end diff --git a/Pod/Classes/Plugin/DoricNavigatorPlugin.m b/Pod/Classes/Plugin/DoricNavigatorPlugin.m index 3086e571..16689502 100644 --- a/Pod/Classes/Plugin/DoricNavigatorPlugin.m +++ b/Pod/Classes/Plugin/DoricNavigatorPlugin.m @@ -24,10 +24,19 @@ @implementation DoricNavigatorPlugin - (void)push:(NSDictionary *)params { dispatch_async(dispatch_get_main_queue(), ^{ BOOL animated = YES; - if (params[@"animated"]) { - animated = [params[@"animated"] boolValue]; + NSString *scheme = params[@"scheme"]; + NSString *alias = scheme; + NSDictionary *config = params[@"config"]; + if (config) { + if (config[@"animated"]) { + animated = [config[@"animated"] boolValue]; + } + + if (config[@"alias"]) { + alias = config[@"alias"]; + } } - [self.doricContext.navigator doric_navigator_push:params[@"scheme"] alias:params[@"alias"] animated:animated]; + [self.doricContext.navigator doric_navigator_push:scheme alias:alias animated:animated extra:config[@"extra"]]; }); }