react-native-navigation的迁移库

RNNNavigationOptions.m 5.2KB

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