123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105 |
- #import "RNNNavigationOptions.h"
- #import <React/RCTConvert.h>
-
-
- @implementation RNNNavigationOptions
-
- -(instancetype)init {
- return [self initWithDict:@{}];
- }
-
- -(instancetype)initWithDict:(NSDictionary *)navigationOptions {
- self = [super init];
- self.topBarBackgroundColor = [navigationOptions objectForKey:@"topBarBackgroundColor"];
- self.statusBarHidden = [navigationOptions objectForKey:@"statusBarHidden"];
- self.title = [navigationOptions objectForKey:@"title"];
- self.topBarTextColor = [navigationOptions objectForKey:@"topBarTextColor"];
- self.screenBackgroundColor = [navigationOptions objectForKey:@"screenBackgroundColor"];
- self.topBarTextFontFamily = [navigationOptions objectForKey:@"topBarTextFontFamily"];
- self.topBarHidden = [navigationOptions objectForKey:@"topBarHidden"];
- self.topBarHideOnScroll = [navigationOptions objectForKey:@"topBarHideOnScroll"];
- self.topBarButtonColor = [navigationOptions objectForKey:@"topBarButtonColor"];
- self.topBarTranslucent = [navigationOptions objectForKey:@"topBarTranslucent"];
- self.setTabBadge = [navigationOptions objectForKey:@"setTabBadge"];
-
- return self;
- }
-
- -(void)mergeWith:(NSDictionary *)otherOptions {
- for (id key in otherOptions) {
- [self setValue:[otherOptions objectForKey:key] forKey:key];
- }
- }
-
- -(void)applyOn:(UIViewController*)viewController {
- if (self.topBarBackgroundColor) {
- UIColor* backgroundColor = [RCTConvert UIColor:self.topBarBackgroundColor];
- viewController.navigationController.navigationBar.barTintColor = backgroundColor;
- } else {
- viewController.navigationController.navigationBar.barTintColor = nil;
- }
-
- if (self.title) {
- viewController.navigationItem.title = self.title;
- }
-
- if (self.topBarTextColor) {
- UIColor* textColor = [RCTConvert UIColor:self.topBarTextColor];
- NSMutableDictionary* navigationBarTitleTextAttributes = [NSMutableDictionary dictionaryWithDictionary:@{NSForegroundColorAttributeName: textColor}];
- if (self.topBarTextFontFamily) {
- [navigationBarTitleTextAttributes addEntriesFromDictionary:@{NSFontAttributeName: [UIFont fontWithName:self.topBarTextFontFamily size:20]}];
- }
- viewController.navigationController.navigationBar.titleTextAttributes = navigationBarTitleTextAttributes;
- } else if (self.topBarTextFontFamily){
- viewController.navigationController.navigationBar.titleTextAttributes = @{NSFontAttributeName: [UIFont fontWithName:self.topBarTextFontFamily size:20]};
- }
-
- if (self.screenBackgroundColor) {
- UIColor* screenColor = [RCTConvert UIColor:self.screenBackgroundColor];
- viewController.view.backgroundColor = screenColor;
- }
-
- if (self.topBarHidden){
- if ([self.topBarHidden boolValue]) {
- [viewController.navigationController setNavigationBarHidden:YES animated:YES];
- } else {
- [viewController.navigationController setNavigationBarHidden:NO animated:YES];
- }
- }
-
- if (self.topBarHideOnScroll) {
- BOOL topBarHideOnScrollBool = [self.topBarHideOnScroll boolValue];
- if (topBarHideOnScrollBool) {
- viewController.navigationController.hidesBarsOnSwipe = YES;
- } else {
- viewController.navigationController.hidesBarsOnSwipe = NO;
- }
- }
-
- if (self.topBarButtonColor) {
- UIColor* buttonColor = [RCTConvert UIColor:self.topBarButtonColor];
- viewController.navigationController.navigationBar.tintColor = buttonColor;
- } else {
- viewController.navigationController.navigationBar.tintColor = nil;
-
- if (self.setTabBadge) {
- NSString *badge = [RCTConvert NSString:self.setTabBadge];
- if (viewController.navigationController) {
- viewController.navigationController.tabBarItem.badgeValue = badge;
- } else {
- viewController.tabBarItem.badgeValue = badge;
- }
-
- }
-
- if (self.topBarTranslucent) {
- if ([self.topBarTranslucent boolValue]) {
- viewController.navigationController.navigationBar.translucent = YES;
- } else {
- viewController.navigationController.navigationBar.translucent = NO;
- }
- }
- }
- }
- @end
|