react-native-navigation的迁移库

RNNNavigationOptions.m 5.1KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143
  1. #import "RNNNavigationOptions.h"
  2. #import <React/RCTConvert.h>
  3. const NSInteger BLUR_STATUS_TAG = 78264801;
  4. @implementation RNNNavigationOptions
  5. -(instancetype)init {
  6. return [self initWithDict:@{}];
  7. }
  8. -(instancetype)initWithDict:(NSDictionary *)navigationOptions {
  9. self = [super init];
  10. self.topBarBackgroundColor = [navigationOptions objectForKey:@"topBarBackgroundColor"];
  11. self.statusBarHidden = [navigationOptions objectForKey:@"statusBarHidden"];
  12. self.title = [navigationOptions objectForKey:@"title"];
  13. self.topBarTextColor = [navigationOptions objectForKey:@"topBarTextColor"];
  14. self.screenBackgroundColor = [navigationOptions objectForKey:@"screenBackgroundColor"];
  15. self.topBarTextFontFamily = [navigationOptions objectForKey:@"topBarTextFontFamily"];
  16. self.topBarHidden = [navigationOptions objectForKey:@"topBarHidden"];
  17. self.topBarHideOnScroll = [navigationOptions objectForKey:@"topBarHideOnScroll"];
  18. self.topBarButtonColor = [navigationOptions objectForKey:@"topBarButtonColor"];
  19. self.topBarTranslucent = [navigationOptions objectForKey:@"topBarTranslucent"];
  20. self.tabBadge = [navigationOptions objectForKey:@"tabBadge"];
  21. self.topBarTextFontSize = [navigationOptions objectForKey:@"topBarTextFontSize"];
  22. self.leftButtons = [navigationOptions objectForKey:@"leftButtons"];
  23. self.rightButtons = [navigationOptions objectForKey:@"rightButtons"];
  24. self.topBarNoBorder = [navigationOptions objectForKey:@"topBarNoBorder"];
  25. return self;
  26. }
  27. -(void)mergeWith:(NSDictionary *)otherOptions {
  28. for (id key in otherOptions) {
  29. [self setValue:[otherOptions objectForKey:key] forKey:key];
  30. }
  31. }
  32. -(void)applyOn:(UIViewController*)viewController {
  33. if (self.topBarBackgroundColor) {
  34. UIColor* backgroundColor = [RCTConvert UIColor:self.topBarBackgroundColor];
  35. viewController.navigationController.navigationBar.barTintColor = backgroundColor;
  36. } else {
  37. viewController.navigationController.navigationBar.barTintColor = nil;
  38. }
  39. if (self.title) {
  40. viewController.navigationItem.title = self.title;
  41. }
  42. if (self.topBarTextFontFamily || self.topBarTextColor || self.topBarTextFontSize){
  43. NSMutableDictionary* navigationBarTitleTextAttributes = [NSMutableDictionary new];
  44. if (self.topBarTextColor) {
  45. navigationBarTitleTextAttributes[NSForegroundColorAttributeName] = [RCTConvert UIColor:self.topBarTextColor];
  46. }
  47. if (self.topBarTextFontFamily){
  48. if(self.topBarTextFontSize) {
  49. navigationBarTitleTextAttributes[NSFontAttributeName] = [UIFont fontWithName:self.topBarTextFontFamily size:[self.topBarTextFontSize floatValue]];
  50. } else {
  51. navigationBarTitleTextAttributes[NSFontAttributeName] = [UIFont fontWithName:self.topBarTextFontFamily size:20];
  52. }
  53. } else if (self.topBarTextFontSize) {
  54. navigationBarTitleTextAttributes[NSFontAttributeName] = [UIFont systemFontOfSize:[self.topBarTextFontSize floatValue]];
  55. }
  56. viewController.navigationController.navigationBar.titleTextAttributes = navigationBarTitleTextAttributes;
  57. }
  58. if (self.screenBackgroundColor) {
  59. UIColor* screenColor = [RCTConvert UIColor:self.screenBackgroundColor];
  60. viewController.view.backgroundColor = screenColor;
  61. }
  62. if (self.topBarHidden){
  63. if ([self.topBarHidden boolValue]) {
  64. [viewController.navigationController setNavigationBarHidden:YES animated:YES];
  65. } else {
  66. [viewController.navigationController setNavigationBarHidden:NO animated:YES];
  67. }
  68. }
  69. if (self.topBarHideOnScroll) {
  70. BOOL topBarHideOnScrollBool = [self.topBarHideOnScroll boolValue];
  71. if (topBarHideOnScrollBool) {
  72. viewController.navigationController.hidesBarsOnSwipe = YES;
  73. } else {
  74. viewController.navigationController.hidesBarsOnSwipe = NO;
  75. }
  76. }
  77. if (self.topBarButtonColor) {
  78. UIColor* buttonColor = [RCTConvert UIColor:self.topBarButtonColor];
  79. viewController.navigationController.navigationBar.tintColor = buttonColor;
  80. } else {
  81. viewController.navigationController.navigationBar.tintColor = nil;
  82. }
  83. if (self.tabBadge) {
  84. NSString *badge = [RCTConvert NSString:self.tabBadge];
  85. if (viewController.navigationController) {
  86. viewController.navigationController.tabBarItem.badgeValue = badge;
  87. } else {
  88. viewController.tabBarItem.badgeValue = badge;
  89. }
  90. }
  91. if (self.topBarTranslucent) {
  92. if ([self.topBarTranslucent boolValue]) {
  93. viewController.navigationController.navigationBar.translucent = YES;
  94. } else {
  95. viewController.navigationController.navigationBar.translucent = NO;
  96. }
  97. }
  98. if (self.topBarNoBorder) {
  99. if ([self.topBarNoBorder boolValue]) {
  100. viewController.navigationController.navigationBar
  101. .shadowImage = [[UIImage alloc] init];
  102. } else {
  103. viewController.navigationController.navigationBar
  104. .shadowImage = nil;
  105. }
  106. }
  107. if (self.statusBarBlur) {
  108. UIView* curBlurView = [viewController.view viewWithTag:BLUR_STATUS_TAG];
  109. if ([self.statusBarBlur boolValue]) {
  110. if (!curBlurView) {
  111. UIVisualEffectView *blur = [[UIVisualEffectView alloc] initWithEffect:[UIBlurEffect effectWithStyle:UIBlurEffectStyleLight]];
  112. blur.frame = [[UIApplication sharedApplication] statusBarFrame];
  113. blur.tag = BLUR_STATUS_TAG;
  114. [viewController.view insertSubview:blur atIndex:0];
  115. }
  116. } else {
  117. if (curBlurView) {
  118. [curBlurView removeFromSuperview];
  119. }
  120. }
  121. }
  122. }
  123. @end