react-native-navigation的迁移库

RNNNavigationOptions.m 5.5KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139
  1. #import "RNNNavigationOptions.h"
  2. #import <React/RCTConvert.h>
  3. #import "RNNNavigationController.h"
  4. #import "RNNTabBarController.h"
  5. #import "RNNTopBarOptions.h"
  6. #import "RNNSideMenuController.h"
  7. #import "RNNRootViewController.h"
  8. #import "RNNNavigationButtons.h"
  9. const NSInteger BLUR_STATUS_TAG = 78264801;
  10. const NSInteger BLUR_TOPBAR_TAG = 78264802;
  11. const NSInteger TOP_BAR_TRANSPARENT_TAG = 78264803;
  12. @implementation RNNNavigationOptions
  13. -(instancetype)init {
  14. return [self initWithDict:@{}];
  15. }
  16. -(instancetype)initWithDict:(NSDictionary *)options {
  17. self = [super init];
  18. self.statusBarHidden = [options objectForKey:@"statusBarHidden"];
  19. self.screenBackgroundColor = [options objectForKey:@"screenBackgroundColor"];
  20. self.backButtonTransition = [options objectForKey:@"backButtonTransition"];
  21. self.orientation = [options objectForKey:@"orientation"];
  22. self.topBar = [[RNNTopBarOptions alloc] initWithDict:[options objectForKey:@"topBar"]];
  23. self.topTab = [[RNNTopTabOptions alloc] initWithDict:[options objectForKey:@"topTab"]];
  24. self.bottomTabs = [[RNNBottomTabsOptions alloc] initWithDict:[options objectForKey:@"bottomTabs"]];
  25. self.sideMenu = [[RNNSideMenuOptions alloc] initWithDict:[options objectForKey:@"sideMenu"]];
  26. self.backgroundImage = [RCTConvert UIImage:[options objectForKey:@"backgroundImage"]];
  27. self.rootBackgroundImage = [RCTConvert UIImage:[options objectForKey:@"rootBackgroundImage"]];
  28. self.bottomTab = [[RNNBottomTabOptions alloc] initWithDict:[options objectForKey:@"bottomTab"]];
  29. self.overlay = [[RNNOverlayOptions alloc] initWithDict:[options objectForKey:@"overlay"]];
  30. return self;
  31. }
  32. -(void)mergeWith:(NSDictionary *)otherOptions {
  33. for (id key in otherOptions) {
  34. if ([[self valueForKey:key] isKindOfClass:[RNNOptions class]]) {
  35. RNNOptions* options = [self valueForKey:key];
  36. [options mergeWith:[otherOptions objectForKey:key]];
  37. } else {
  38. [self setValue:[otherOptions objectForKey:key] forKey:key];
  39. }
  40. }
  41. }
  42. -(void)applyOn:(UIViewController*)viewController {
  43. [_defaultOptions applyOn:viewController];
  44. [self.topBar applyOn:viewController];
  45. [self.bottomTabs applyOn:viewController];
  46. [self.topTab applyOn:viewController];
  47. [self.bottomTab applyOn:viewController];
  48. [self.sideMenu applyOn:viewController];
  49. [self.overlay applyOn:viewController];
  50. [self applyOtherOptionsOn:viewController];
  51. }
  52. - (void)applyOtherOptionsOn:(UIViewController*)viewController {
  53. if (self.popGesture) {
  54. viewController.navigationController.interactivePopGestureRecognizer.enabled = [self.popGesture boolValue];
  55. }
  56. if (self.screenBackgroundColor) {
  57. UIColor* screenColor = [RCTConvert UIColor:self.screenBackgroundColor];
  58. viewController.view.backgroundColor = screenColor;
  59. }
  60. if (self.statusBarBlur) {
  61. UIView* curBlurView = [viewController.view viewWithTag:BLUR_STATUS_TAG];
  62. if ([self.statusBarBlur boolValue]) {
  63. if (!curBlurView) {
  64. UIVisualEffectView *blur = [[UIVisualEffectView alloc] initWithEffect:[UIBlurEffect effectWithStyle:UIBlurEffectStyleLight]];
  65. blur.frame = [[UIApplication sharedApplication] statusBarFrame];
  66. blur.tag = BLUR_STATUS_TAG;
  67. [viewController.view insertSubview:blur atIndex:0];
  68. }
  69. } else {
  70. if (curBlurView) {
  71. [curBlurView removeFromSuperview];
  72. }
  73. }
  74. }
  75. if (self.backgroundImage) {
  76. UIImageView* backgroundImageView = (viewController.view.subviews.count > 0) ? viewController.view.subviews[0] : nil;
  77. if (![backgroundImageView isKindOfClass:[UIImageView class]]) {
  78. backgroundImageView = [[UIImageView alloc] initWithFrame:viewController.view.bounds];
  79. [viewController.view insertSubview:backgroundImageView atIndex:0];
  80. }
  81. backgroundImageView.layer.masksToBounds = YES;
  82. backgroundImageView.image = self.backgroundImage;
  83. [backgroundImageView setContentMode:UIViewContentModeScaleAspectFill];
  84. }
  85. if (self.rootBackgroundImage) {
  86. UIImageView* backgroundImageView = (viewController.navigationController.view.subviews.count > 0) ? viewController.navigationController.view.subviews[0] : nil;
  87. if (![backgroundImageView isKindOfClass:[UIImageView class]]) {
  88. backgroundImageView = [[UIImageView alloc] initWithFrame:viewController.view.bounds];
  89. [viewController.navigationController.view insertSubview:backgroundImageView atIndex:0];
  90. }
  91. backgroundImageView.layer.masksToBounds = YES;
  92. backgroundImageView.image = self.rootBackgroundImage;
  93. [backgroundImageView setContentMode:UIViewContentModeScaleAspectFill];
  94. }
  95. }
  96. - (UIInterfaceOrientationMask)supportedOrientations {
  97. NSArray* orientationsArray = [self.orientation isKindOfClass:[NSString class]] ? @[self.orientation] : self.orientation;
  98. NSUInteger supportedOrientationsMask = 0;
  99. if (!orientationsArray || [self.orientation isEqual:@"default"]) {
  100. return [[UIApplication sharedApplication] supportedInterfaceOrientationsForWindow:[[UIApplication sharedApplication] keyWindow]];
  101. } else {
  102. for (NSString* orientation in orientationsArray) {
  103. if ([orientation isEqualToString:@"all"]) {
  104. supportedOrientationsMask = UIInterfaceOrientationMaskAll;
  105. break;
  106. }
  107. if ([orientation isEqualToString:@"landscape"]) {
  108. supportedOrientationsMask = (supportedOrientationsMask | UIInterfaceOrientationMaskLandscape);
  109. }
  110. if ([orientation isEqualToString:@"portrait"]) {
  111. supportedOrientationsMask = (supportedOrientationsMask | UIInterfaceOrientationMaskPortrait);
  112. }
  113. if ([orientation isEqualToString:@"upsideDown"]) {
  114. supportedOrientationsMask = (supportedOrientationsMask | UIInterfaceOrientationMaskPortraitUpsideDown);
  115. }
  116. }
  117. }
  118. return supportedOrientationsMask;
  119. }
  120. @end