add Navbar for iOS
This commit is contained in:
parent
713c043f71
commit
28f29d7396
@ -24,4 +24,3 @@
|
||||
#import "DoricJSLoaderManager.h"
|
||||
#import "DoricNavigatorProtocol.h"
|
||||
#import "DoricViewController.h"
|
||||
#import "DoricDefaultNavigator.h"
|
@ -23,13 +23,15 @@
|
||||
#import <Foundation/Foundation.h>
|
||||
#import "DoricDriver.h"
|
||||
#import "DoricNavigatorProtocol.h"
|
||||
#import "DoricNavBarProtocol.h"
|
||||
|
||||
NS_ASSUME_NONNULL_BEGIN
|
||||
|
||||
@class DoricRootNode;
|
||||
|
||||
@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) DoricDriver *driver;
|
||||
@property(nonatomic, strong) NSMutableDictionary *pluginInstanceMap;
|
||||
|
@ -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;
|
||||
|
@ -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"];
|
||||
|
@ -19,7 +19,8 @@
|
||||
|
||||
#import <Foundation/Foundation.h>
|
||||
#import "DoricNavigatorProtocol.h"
|
||||
#import "DoricNavBarProtocol.h"
|
||||
|
||||
@interface DoricViewController : UIViewController
|
||||
@interface DoricViewController : UIViewController <DoricNavigatorProtocol, DoricNavBarProtocol>
|
||||
- (instancetype)initWithScheme:(NSString *)scheme alias:(NSString *)alias;
|
||||
@end
|
@ -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
|
||||
|
31
iOS/Pod/Classes/NavBar/DoricNavBarProtocol.h
Normal file
31
iOS/Pod/Classes/NavBar/DoricNavBarProtocol.h
Normal 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
|
@ -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.
|
||||
//
|
||||
|
26
iOS/Pod/Classes/Plugin/DoricNavBarPlugin.h
Normal file
26
iOS/Pod/Classes/Plugin/DoricNavBarPlugin.h
Normal 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
|
68
iOS/Pod/Classes/Plugin/DoricNavBarPlugin.m
Normal file
68
iOS/Pod/Classes/Plugin/DoricNavBarPlugin.m
Normal 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
|
Reference in New Issue
Block a user