diff --git a/doric-iOS/Pod/Classes/DoricViewController.m b/doric-iOS/Pod/Classes/DoricViewController.m index 18d05bfa..d94c3863 100644 --- a/doric-iOS/Pod/Classes/DoricViewController.m +++ b/doric-iOS/Pod/Classes/DoricViewController.m @@ -103,5 +103,15 @@ - (void)doric_navBar_setBackgroundColor:(UIColor *)color { [self.navigationController.navigationBar setBackgroundImage:UIImageWithColor(color) forBarMetrics:UIBarMetricsDefault]; } +- (void)doric_navBar_setLeft:(UIView *)view { + UIBarButtonItem *custom = [[UIBarButtonItem alloc] initWithCustomView:view]; + self.navigationItem.leftBarButtonItem = custom; +} + +- (void)doric_navBar_setRight:(UIView *)view { + UIBarButtonItem *custom = [[UIBarButtonItem alloc] initWithCustomView:view]; + self.navigationItem.rightBarButtonItem = custom; +} + @end diff --git a/doric-iOS/Pod/Classes/NavBar/DoricNavBarDelegate.h b/doric-iOS/Pod/Classes/NavBar/DoricNavBarDelegate.h index bb9745b9..aa466897 100644 --- a/doric-iOS/Pod/Classes/NavBar/DoricNavBarDelegate.h +++ b/doric-iOS/Pod/Classes/NavBar/DoricNavBarDelegate.h @@ -28,4 +28,8 @@ - (void)doric_navBar_setTitle:(NSString *)title; - (void)doric_navBar_setBackgroundColor:(UIColor *)color; + +- (void)doric_navBar_setLeft:(UIView *)view; + +- (void)doric_navBar_setRight:(UIView *)view; @end diff --git a/doric-iOS/Pod/Classes/Plugin/DoricNavBarPlugin.m b/doric-iOS/Pod/Classes/Plugin/DoricNavBarPlugin.m index 46399c64..d6bc2fe2 100644 --- a/doric-iOS/Pod/Classes/Plugin/DoricNavBarPlugin.m +++ b/doric-iOS/Pod/Classes/Plugin/DoricNavBarPlugin.m @@ -19,8 +19,14 @@ #import "DoricNavBarPlugin.h" #import "DoricUtil.h" +#import "DoricViewNode.h" +#import "DoricExtensions.h" @implementation DoricNavBarPlugin + +static NSString *TYPE_LEFT = @"navbar_left"; +static NSString *TYPE_RIGHT = @"navbar_right"; + - (void)isHidden:(NSDictionary *)param withPromise:(DoricPromise *)promise { if (self.doricContext.navBar) { dispatch_async(dispatch_get_main_queue(), ^{ @@ -65,4 +71,66 @@ - (void)setBgColor:(NSDictionary *)param withPromise:(DoricPromise *)promise { } } +- (void)setLeft:(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.layoutConfig = [DoricLayoutConfig new]; + [self.doricContext.navBar doric_navBar_setLeft:it.view]; + + NSMutableDictionary *map = self.doricContext.headNodes[TYPE_LEFT]; + if (map != nil) { + self.doricContext.headNodes[TYPE_LEFT][viewId] = it; + } else { + map = [[NSMutableDictionary alloc] init]; + map[viewId] = it; + self.doricContext.headNodes[TYPE_LEFT] = map; + } + }]; + } + [viewNode blend:params[@"props"]]; + [promise resolve:nil]; + }); + } else { + [promise reject:@"Not implement NavBar"]; + } +} + +- (void)setRight:(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.layoutConfig = [DoricLayoutConfig new]; + [self.doricContext.navBar doric_navBar_setRight:it.view]; + + NSMutableDictionary *map = self.doricContext.headNodes[TYPE_RIGHT]; + if (map != nil) { + self.doricContext.headNodes[TYPE_RIGHT][viewId] = it; + } else { + map = [[NSMutableDictionary alloc] init]; + map[viewId] = it; + self.doricContext.headNodes[TYPE_RIGHT] = map; + } + }]; + } + [viewNode blend:params[@"props"]]; + [promise resolve:nil]; + }); + } else { + [promise reject:@"Not implement NavBar"]; + } +} + @end