diff --git a/iOS/Pod/Classes/Doric.h b/iOS/Pod/Classes/Doric.h index ef285e59..9df6d257 100644 --- a/iOS/Pod/Classes/Doric.h +++ b/iOS/Pod/Classes/Doric.h @@ -23,5 +23,4 @@ #import "DoricPanel.h" #import "DoricJSLoaderManager.h" #import "DoricNavigatorProtocol.h" -#import "DoricViewController.h" -#import "DoricDefaultNavigator.h" \ No newline at end of file +#import "DoricViewController.h" \ No newline at end of file diff --git a/iOS/Pod/Classes/DoricContext.h b/iOS/Pod/Classes/DoricContext.h index e511ab77..80a58738 100644 --- a/iOS/Pod/Classes/DoricContext.h +++ b/iOS/Pod/Classes/DoricContext.h @@ -23,13 +23,15 @@ #import #import "DoricDriver.h" #import "DoricNavigatorProtocol.h" +#import "DoricNavBarProtocol.h" NS_ASSUME_NONNULL_BEGIN @class DoricRootNode; @interface DoricContext : NSObject -@property(nonatomic, strong) id navigator; +@property(nonatomic, weak) id navigator; +@property(nonatomic, weak) id navBar; @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 9eadcce8..1ad24ff2 100644 --- a/iOS/Pod/Classes/DoricPanel.m +++ b/iOS/Pod/Classes/DoricPanel.m @@ -24,7 +24,6 @@ @implementation DoricPanel - (void)config:(NSString *)script alias:(NSString *)alias { self.doricContext = [[[DoricContext alloc] initWithScript:script source:alias] also:^(DoricContext *it) { - 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/DoricRegistry.m b/iOS/Pod/Classes/DoricRegistry.m index 99a0ca3b..c3e84485 100644 --- a/iOS/Pod/Classes/DoricRegistry.m +++ b/iOS/Pod/Classes/DoricRegistry.m @@ -36,6 +36,7 @@ #import "DoricSlideItemNode.h" #import "DoricStoragePlugin.h" #import "DoricNavigatorPlugin.h" +#import "DoricNavBarPlugin.h" @interface DoricRegistry () @@ -63,6 +64,7 @@ - (void)innerRegister { [self registerNativePlugin:DoricNetworkPlugin.class withName:@"network"]; [self registerNativePlugin:DoricStoragePlugin.class withName:@"storage"]; [self registerNativePlugin:DoricNavigatorPlugin.class withName:@"navigator"]; + [self registerNativePlugin:DoricNavBarPlugin.class withName:@"navbar"]; [self registerViewNode:DoricStackNode.class withName:@"Stack"]; [self registerViewNode:DoricVLayoutNode.class withName:@"VLayout"]; diff --git a/iOS/Pod/Classes/DoricViewController.h b/iOS/Pod/Classes/DoricViewController.h index 590dc5fd..0faa8d4e 100644 --- a/iOS/Pod/Classes/DoricViewController.h +++ b/iOS/Pod/Classes/DoricViewController.h @@ -19,7 +19,8 @@ #import #import "DoricNavigatorProtocol.h" +#import "DoricNavBarProtocol.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 bfbadd7e..e7b58d5e 100644 --- a/iOS/Pod/Classes/DoricViewController.m +++ b/iOS/Pod/Classes/DoricViewController.m @@ -40,10 +40,34 @@ - (instancetype)initWithScheme:(NSString *)scheme alias:(NSString *)alias { [self.view addSubview:panel.view]; [self addChildViewController:panel]; [panel config:result alias:alias]; - + panel.doricContext.navigator = self; + panel.doricContext.navBar = 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]; +} + +- (BOOL)isHidden { + return self.navigationController.navigationBarHidden; +} + +- (void)setHidden:(BOOL)hidden { + [self.navigationController setNavigationBarHidden:hidden]; +} + +- (void)setBackgroundColor:(UIColor *)color { + [self.navigationController.navigationBar setBackgroundColor:color]; +} + + @end diff --git a/iOS/Pod/Classes/NavBar/DoricNavBarProtocol.h b/iOS/Pod/Classes/NavBar/DoricNavBarProtocol.h new file mode 100644 index 00000000..e4ef9e87 --- /dev/null +++ b/iOS/Pod/Classes/NavBar/DoricNavBarProtocol.h @@ -0,0 +1,31 @@ +/* + * Copyright [2019] [Doric.Pub] + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * 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, + * 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. + */ +// +// Created by pengfei.zhou on 2019/11/25. +// + +#import + + +@protocol DoricNavBarProtocol +- (BOOL)isHidden; + +- (void)setHidden:(BOOL)hidden; + +- (void)setTitle:(NSString *)title; + +- (void)setBackgroundColor:(UIColor *)color; +@end \ No newline at end of file diff --git a/iOS/Pod/Classes/Navigator/DoricNavigatorProtocol.h b/iOS/Pod/Classes/Navigator/DoricNavigatorProtocol.h index ba87e713..0dba960d 100644 --- a/iOS/Pod/Classes/Navigator/DoricNavigatorProtocol.h +++ b/iOS/Pod/Classes/Navigator/DoricNavigatorProtocol.h @@ -1,3 +1,18 @@ +/* + * Copyright [2019] [Doric.Pub] + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * 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, + * 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. + */ // // Created by pengfei.zhou on 2019/11/23. // diff --git a/iOS/Pod/Classes/Plugin/DoricNavBarPlugin.h b/iOS/Pod/Classes/Plugin/DoricNavBarPlugin.h new file mode 100644 index 00000000..5b214edc --- /dev/null +++ b/iOS/Pod/Classes/Plugin/DoricNavBarPlugin.h @@ -0,0 +1,26 @@ +/* + * Copyright [2019] [Doric.Pub] + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * 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, + * 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. + */ +// +// Created by pengfei.zhou on 2019/11/25. +// + +#import + +#import "DoricNativePlugin.h" + +@interface DoricNavBarPlugin : DoricNativePlugin + +@end \ No newline at end of file diff --git a/iOS/Pod/Classes/Plugin/DoricNavBarPlugin.m b/iOS/Pod/Classes/Plugin/DoricNavBarPlugin.m new file mode 100644 index 00000000..5d801226 --- /dev/null +++ b/iOS/Pod/Classes/Plugin/DoricNavBarPlugin.m @@ -0,0 +1,68 @@ +/* + * Copyright [2019] [Doric.Pub] + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * 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, + * 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. + */ +// +// Created by pengfei.zhou on 2019/11/25. +// + +#import "DoricNavBarPlugin.h" +#import "DoricUtil.h" + +@implementation DoricNavBarPlugin +- (void)isHidden:(NSDictionary *)param withPromise:(DoricPromise *)promise { + if (self.doricContext.navBar) { + dispatch_async(dispatch_get_main_queue(), ^{ + [promise resolve:@([self.doricContext.navBar isHidden])]; + }); + } else { + [promise reject:@"Not implement NavBar"]; + } +} + +- (void)setHidden:(NSDictionary *)param withPromise:(DoricPromise *)promise { + if (self.doricContext.navBar) { + dispatch_async(dispatch_get_main_queue(), ^{ + [self.doricContext.navBar setHidden:[param[@"hidden"] boolValue]]; + [promise resolve:nil]; + }); + } else { + [promise reject:@"Not implement NavBar"]; + } +} + +- (void)setTitle:(NSDictionary *)param withPromise:(DoricPromise *)promise { + if (self.doricContext.navBar) { + dispatch_async(dispatch_get_main_queue(), ^{ + [self.doricContext.navBar setTitle:param[@"title"]]; + [promise resolve:nil]; + }); + } else { + [promise reject:@"Not implement NavBar"]; + } +} + +- (void)setBgColor:(NSDictionary *)param withPromise:(DoricPromise *)promise { + if (self.doricContext.navBar) { + dispatch_async(dispatch_get_main_queue(), ^{ + UIColor *color = DoricColor(param[@"color"]); + [self.doricContext.navBar setBackgroundColor:color]; + [promise resolve:nil]; + }); + } else { + [promise reject:@"Not implement NavBar"]; + } +} + +@end