From 2e9459f80f63a45d4684bcde39f4be18623774b9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=8E=8B=E5=8A=B2=E9=B9=8F?= Date: Thu, 30 Apr 2020 16:37:06 +0800 Subject: [PATCH] iOS: implements navbar set center --- doric-iOS/Pod/Classes/DoricViewController.m | 4 +++ .../Pod/Classes/NavBar/DoricNavBarDelegate.h | 2 ++ .../Pod/Classes/Plugin/DoricNavBarPlugin.m | 32 +++++++++++++++++++ 3 files changed, 38 insertions(+) diff --git a/doric-iOS/Pod/Classes/DoricViewController.m b/doric-iOS/Pod/Classes/DoricViewController.m index 107d93ee..ba5e2277 100644 --- a/doric-iOS/Pod/Classes/DoricViewController.m +++ b/doric-iOS/Pod/Classes/DoricViewController.m @@ -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; } diff --git a/doric-iOS/Pod/Classes/NavBar/DoricNavBarDelegate.h b/doric-iOS/Pod/Classes/NavBar/DoricNavBarDelegate.h index aa466897..708d51cc 100644 --- a/doric-iOS/Pod/Classes/NavBar/DoricNavBarDelegate.h +++ b/doric-iOS/Pod/Classes/NavBar/DoricNavBarDelegate.h @@ -32,4 +32,6 @@ - (void)doric_navBar_setLeft:(UIView *)view; - (void)doric_navBar_setRight:(UIView *)view; + +- (void)doric_navBar_setCenter:(UIView *)view; @end diff --git a/doric-iOS/Pod/Classes/Plugin/DoricNavBarPlugin.m b/doric-iOS/Pod/Classes/Plugin/DoricNavBarPlugin.m index d9095a26..37a0b86b 100644 --- a/doric-iOS/Pod/Classes/Plugin/DoricNavBarPlugin.m +++ b/doric-iOS/Pod/Classes/Plugin/DoricNavBarPlugin.m @@ -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 *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