add Navbar for iOS

This commit is contained in:
pengfei.zhou 2019-11-25 14:20:18 +08:00
parent 713c043f71
commit 28f29d7396
10 changed files with 173 additions and 6 deletions

View File

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

View File

@ -23,13 +23,15 @@
#import <Foundation/Foundation.h> #import <Foundation/Foundation.h>
#import "DoricDriver.h" #import "DoricDriver.h"
#import "DoricNavigatorProtocol.h" #import "DoricNavigatorProtocol.h"
#import "DoricNavBarProtocol.h"
NS_ASSUME_NONNULL_BEGIN NS_ASSUME_NONNULL_BEGIN
@class DoricRootNode; @class DoricRootNode;
@interface DoricContext : NSObject @interface DoricContext : NSObject
@property(nonatomic, strong) id <DoricNavigatorProtocol> navigator; @property(nonatomic, weak) id <DoricNavigatorProtocol> navigator;
@property(nonatomic, weak) id <DoricNavBarProtocol> navBar;
@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,7 +24,6 @@ @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) {
it.navigator = [[DoricDefaultNavigator alloc] initWithNavigationController:self.navigationController];
[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

@ -36,6 +36,7 @@
#import "DoricSlideItemNode.h" #import "DoricSlideItemNode.h"
#import "DoricStoragePlugin.h" #import "DoricStoragePlugin.h"
#import "DoricNavigatorPlugin.h" #import "DoricNavigatorPlugin.h"
#import "DoricNavBarPlugin.h"
@interface DoricRegistry () @interface DoricRegistry ()
@ -63,6 +64,7 @@ - (void)innerRegister {
[self registerNativePlugin:DoricNetworkPlugin.class withName:@"network"]; [self registerNativePlugin:DoricNetworkPlugin.class withName:@"network"];
[self registerNativePlugin:DoricStoragePlugin.class withName:@"storage"]; [self registerNativePlugin:DoricStoragePlugin.class withName:@"storage"];
[self registerNativePlugin:DoricNavigatorPlugin.class withName:@"navigator"]; [self registerNativePlugin:DoricNavigatorPlugin.class withName:@"navigator"];
[self registerNativePlugin:DoricNavBarPlugin.class withName:@"navbar"];
[self registerViewNode:DoricStackNode.class withName:@"Stack"]; [self registerViewNode:DoricStackNode.class withName:@"Stack"];
[self registerViewNode:DoricVLayoutNode.class withName:@"VLayout"]; [self registerViewNode:DoricVLayoutNode.class withName:@"VLayout"];

View File

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

View File

@ -40,10 +40,34 @@ - (instancetype)initWithScheme:(NSString *)scheme alias:(NSString *)alias {
[self.view addSubview:panel.view]; [self.view addSubview:panel.view];
[self addChildViewController:panel]; [self addChildViewController:panel];
[panel config:result alias:alias]; [panel config:result alias:alias];
panel.doricContext.navigator = self;
panel.doricContext.navBar = self;
}); });
}; };
} }
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];
}
- (BOOL)isHidden {
return self.navigationController.navigationBarHidden;
}
- (void)setHidden:(BOOL)hidden {
[self.navigationController setNavigationBarHidden:hidden];
}
- (void)setBackgroundColor:(UIColor *)color {
[self.navigationController.navigationBar setBackgroundColor:color];
}
@end @end

View File

@ -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 <Foundation/Foundation.h>
@protocol DoricNavBarProtocol <NSObject>
- (BOOL)isHidden;
- (void)setHidden:(BOOL)hidden;
- (void)setTitle:(NSString *)title;
- (void)setBackgroundColor:(UIColor *)color;
@end

View File

@ -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. // Created by pengfei.zhou on 2019/11/23.
// //

View File

@ -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 <Foundation/Foundation.h>
#import "DoricNativePlugin.h"
@interface DoricNavBarPlugin : DoricNativePlugin
@end

View File

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