react-native-navigation的迁移库

RNNNavigationOptions.m 5.9KB

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