react-native-navigation的迁移库

RNNNavigationOptions.m 6.1KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156
  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. self.animated = [options objectForKey:@"animated"];
  31. self.customTransition = [[RNNAnimationOptions alloc] initWithDict:[options objectForKey:@"customTransition"]];
  32. return self;
  33. }
  34. -(void)mergeWith:(NSDictionary *)otherOptions {
  35. for (id key in otherOptions) {
  36. if ([self hasProperty:key]) {
  37. if ([[self valueForKey:key] isKindOfClass:[RNNOptions class]]) {
  38. RNNOptions* options = [self valueForKey:key];
  39. [options mergeWith:[otherOptions objectForKey:key]];
  40. } else {
  41. [self setValue:[otherOptions objectForKey:key] forKey:key];
  42. }
  43. }
  44. }
  45. }
  46. -(void)mergeIfEmptyWith:(NSDictionary *)otherOptions {
  47. for (id key in otherOptions) {
  48. if ([self hasProperty:key]) {
  49. if ([[self valueForKey:key] isKindOfClass:[RNNOptions class]]) {
  50. RNNOptions* options = [self valueForKey:key];
  51. [options mergeIfEmptyWith:[otherOptions objectForKey:key]];
  52. } else if (![self valueForKey:key]) {
  53. [self setValue:[otherOptions objectForKey:key] forKey:key];
  54. }
  55. }
  56. }
  57. }
  58. -(void)applyOn:(UIViewController*)viewController {
  59. [_defaultOptions applyOn:viewController];
  60. [self.topBar applyOn:viewController];
  61. [self.bottomTabs applyOn:viewController];
  62. [self.topTab applyOn:viewController];
  63. [self.bottomTab applyOn:viewController];
  64. [self.sideMenu applyOn:viewController];
  65. [self.overlay applyOn:viewController];
  66. [self applyOtherOptionsOn:viewController];
  67. }
  68. - (void)applyOtherOptionsOn:(UIViewController*)viewController {
  69. if (self.popGesture) {
  70. viewController.navigationController.interactivePopGestureRecognizer.enabled = [self.popGesture boolValue];
  71. }
  72. if (self.screenBackgroundColor) {
  73. UIColor* screenColor = [RCTConvert UIColor:self.screenBackgroundColor];
  74. viewController.view.backgroundColor = screenColor;
  75. }
  76. if (self.statusBarBlur) {
  77. UIView* curBlurView = [viewController.view viewWithTag:BLUR_STATUS_TAG];
  78. if ([self.statusBarBlur boolValue]) {
  79. if (!curBlurView) {
  80. UIVisualEffectView *blur = [[UIVisualEffectView alloc] initWithEffect:[UIBlurEffect effectWithStyle:UIBlurEffectStyleLight]];
  81. blur.frame = [[UIApplication sharedApplication] statusBarFrame];
  82. blur.tag = BLUR_STATUS_TAG;
  83. [viewController.view insertSubview:blur atIndex:0];
  84. }
  85. } else {
  86. if (curBlurView) {
  87. [curBlurView removeFromSuperview];
  88. }
  89. }
  90. }
  91. if (self.backgroundImage) {
  92. UIImageView* backgroundImageView = (viewController.view.subviews.count > 0) ? viewController.view.subviews[0] : nil;
  93. if (![backgroundImageView isKindOfClass:[UIImageView class]]) {
  94. backgroundImageView = [[UIImageView alloc] initWithFrame:viewController.view.bounds];
  95. [viewController.view insertSubview:backgroundImageView atIndex:0];
  96. }
  97. backgroundImageView.layer.masksToBounds = YES;
  98. backgroundImageView.image = self.backgroundImage;
  99. [backgroundImageView setContentMode:UIViewContentModeScaleAspectFill];
  100. }
  101. if (self.rootBackgroundImage) {
  102. UIImageView* backgroundImageView = (viewController.navigationController.view.subviews.count > 0) ? viewController.navigationController.view.subviews[0] : nil;
  103. if (![backgroundImageView isKindOfClass:[UIImageView class]]) {
  104. backgroundImageView = [[UIImageView alloc] initWithFrame:viewController.view.bounds];
  105. [viewController.navigationController.view insertSubview:backgroundImageView atIndex:0];
  106. }
  107. backgroundImageView.layer.masksToBounds = YES;
  108. backgroundImageView.image = self.rootBackgroundImage;
  109. [backgroundImageView setContentMode:UIViewContentModeScaleAspectFill];
  110. }
  111. }
  112. - (UIInterfaceOrientationMask)supportedOrientations {
  113. NSArray* orientationsArray = [self.orientation isKindOfClass:[NSString class]] ? @[self.orientation] : self.orientation;
  114. NSUInteger supportedOrientationsMask = 0;
  115. if (!orientationsArray || [self.orientation isEqual:@"default"]) {
  116. return [[UIApplication sharedApplication] supportedInterfaceOrientationsForWindow:[[UIApplication sharedApplication] keyWindow]];
  117. } else {
  118. for (NSString* orientation in orientationsArray) {
  119. if ([orientation isEqualToString:@"all"]) {
  120. supportedOrientationsMask = UIInterfaceOrientationMaskAll;
  121. break;
  122. }
  123. if ([orientation isEqualToString:@"landscape"]) {
  124. supportedOrientationsMask = (supportedOrientationsMask | UIInterfaceOrientationMaskLandscape);
  125. }
  126. if ([orientation isEqualToString:@"portrait"]) {
  127. supportedOrientationsMask = (supportedOrientationsMask | UIInterfaceOrientationMaskPortrait);
  128. }
  129. if ([orientation isEqualToString:@"upsideDown"]) {
  130. supportedOrientationsMask = (supportedOrientationsMask | UIInterfaceOrientationMaskPortraitUpsideDown);
  131. }
  132. }
  133. }
  134. return supportedOrientationsMask;
  135. }
  136. @end