iOS: implements navbar set center

This commit is contained in:
王劲鹏 2020-04-30 16:37:06 +08:00 committed by osborn
parent 007786f4ef
commit 2e9459f80f
3 changed files with 38 additions and 0 deletions

View File

@ -134,6 +134,10 @@ - (void)doric_navBar_setRight:(UIView *)view {
self.navigationItem.rightBarButtonItem = custom;
}
- (void)doric_navBar_setCenter:(UIView *)view {
self.navigationItem.titleView = view;
}
- (BOOL)statusBarHidden {
return _statusBarHidden;
}

View File

@ -32,4 +32,6 @@
- (void)doric_navBar_setLeft:(UIView *)view;
- (void)doric_navBar_setRight:(UIView *)view;
- (void)doric_navBar_setCenter:(UIView *)view;
@end

View File

@ -26,6 +26,7 @@ @implementation DoricNavBarPlugin
static NSString *TYPE_LEFT = @"navbar_left";
static NSString *TYPE_RIGHT = @"navbar_right";
static NSString *TYPE_CENTER = @"navbar_center";
- (void)isHidden:(NSDictionary *)param withPromise:(DoricPromise *)promise {
if (self.doricContext.navBar) {
@ -133,4 +134,35 @@ - (void)setRight:(NSDictionary *)params withPromise:(DoricPromise *)promise {
}
}
- (void)setCenter:(NSDictionary *)params withPromise:(DoricPromise *)promise {
if (self.doricContext.navBar) {
dispatch_async(dispatch_get_main_queue(), ^{
NSString *viewId = params[@"id"];
NSString *type = params[@"type"];
DoricViewNode *viewNode = [self.doricContext targetViewNode:viewId];
if (!viewNode) {
viewNode = [[DoricViewNode create:self.doricContext withType:type] also:^(DoricViewNode *it) {
it.viewId = viewId;
[it initWithSuperNode:nil];
it.view.doricLayout = [DoricLayout new];
[self.doricContext.navBar doric_navBar_setCenter:it.view];
NSMutableDictionary <NSString *, DoricViewNode *> *map = self.doricContext.headNodes[TYPE_CENTER];
if (map != nil) {
self.doricContext.headNodes[TYPE_CENTER][viewId] = it;
} else {
map = [[NSMutableDictionary alloc] init];
map[viewId] = it;
self.doricContext.headNodes[TYPE_CENTER] = map;
}
}];
}
[viewNode blend:params[@"props"]];
[promise resolve:nil];
});
} else {
[promise reject:@"Not implement NavBar"];
}
}
@end