react-native-navigation的迁移库

RNNNavigationOptions.m 5.8KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149
  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 RCTConvert (UIModalPresentationStyle)
  13. RCT_ENUM_CONVERTER(UIModalPresentationStyle,
  14. (@{@"fullScreen": @(UIModalPresentationFullScreen),
  15. @"pageSheet": @(UIModalPresentationPageSheet),
  16. @"formSheet": @(UIModalPresentationFormSheet),
  17. @"currentContext": @(UIModalPresentationCurrentContext),
  18. @"custom": @(UIModalPresentationCustom),
  19. @"overFullScreen": @(UIModalPresentationOverFullScreen),
  20. @"overCurrentContext": @(UIModalPresentationOverCurrentContext),
  21. @"popover": @(UIModalPresentationPopover),
  22. @"none": @(UIModalPresentationNone)
  23. }), UIModalPresentationFullScreen, integerValue)
  24. @end
  25. @implementation RCTConvert (UIModalTransitionStyle)
  26. RCT_ENUM_CONVERTER(UIModalTransitionStyle,
  27. (@{@"coverVertical": @(UIModalTransitionStyleCoverVertical),
  28. @"flipHorizontal": @(UIModalTransitionStyleFlipHorizontal),
  29. @"crossDissolve": @(UIModalTransitionStyleCrossDissolve),
  30. @"partialCurl": @(UIModalTransitionStylePartialCurl)
  31. }), UIModalTransitionStyleCoverVertical, integerValue)
  32. @end
  33. @implementation RNNNavigationOptions
  34. -(void)applyOn:(UIViewController<RNNRootViewProtocol> *)viewController {
  35. [self.topBar applyOn:viewController];
  36. [self.bottomTabs applyOn:viewController];
  37. [self.topTab applyOn:viewController];
  38. [self.bottomTab applyOn:viewController];
  39. [self.sideMenu applyOn:viewController];
  40. [self.overlay applyOn:viewController];
  41. [self applyOtherOptionsOn:viewController];
  42. [viewController optionsUpdated];
  43. }
  44. - (void)applyOtherOptionsOn:(UIViewController*)viewController {
  45. if (self.popGesture) {
  46. viewController.navigationController.interactivePopGestureRecognizer.enabled = [self.popGesture boolValue];
  47. }
  48. if (self.screenBackgroundColor) {
  49. UIColor* screenColor = [RCTConvert UIColor:self.screenBackgroundColor];
  50. viewController.view.backgroundColor = screenColor;
  51. }
  52. if (self.statusBarBlur) {
  53. UIView* curBlurView = [viewController.view viewWithTag:BLUR_STATUS_TAG];
  54. if ([self.statusBarBlur boolValue]) {
  55. if (!curBlurView) {
  56. UIVisualEffectView *blur = [[UIVisualEffectView alloc] initWithEffect:[UIBlurEffect effectWithStyle:UIBlurEffectStyleLight]];
  57. blur.frame = [[UIApplication sharedApplication] statusBarFrame];
  58. blur.tag = BLUR_STATUS_TAG;
  59. [viewController.view insertSubview:blur atIndex:0];
  60. }
  61. } else {
  62. if (curBlurView) {
  63. [curBlurView removeFromSuperview];
  64. }
  65. }
  66. }
  67. if (self.backgroundImage) {
  68. UIImageView* backgroundImageView = (viewController.view.subviews.count > 0) ? viewController.view.subviews[0] : nil;
  69. if (![backgroundImageView isKindOfClass:[UIImageView class]]) {
  70. backgroundImageView = [[UIImageView alloc] initWithFrame:viewController.view.bounds];
  71. [viewController.view insertSubview:backgroundImageView atIndex:0];
  72. }
  73. backgroundImageView.layer.masksToBounds = YES;
  74. backgroundImageView.image = [self.backgroundImage isKindOfClass:[UIImage class]] ? (UIImage*)self.backgroundImage : [RCTConvert UIImage:self.backgroundImage];
  75. [backgroundImageView setContentMode:UIViewContentModeScaleAspectFill];
  76. }
  77. if (self.rootBackgroundImage) {
  78. UIImageView* backgroundImageView = (viewController.navigationController.view.subviews.count > 0) ? viewController.navigationController.view.subviews[0] : nil;
  79. if (![backgroundImageView isKindOfClass:[UIImageView class]]) {
  80. backgroundImageView = [[UIImageView alloc] initWithFrame:viewController.view.bounds];
  81. [viewController.navigationController.view insertSubview:backgroundImageView atIndex:0];
  82. }
  83. backgroundImageView.layer.masksToBounds = YES;
  84. backgroundImageView.image = [self.rootBackgroundImage isKindOfClass:[UIImage class]] ? (UIImage*)self.rootBackgroundImage : [RCTConvert UIImage:self.rootBackgroundImage];
  85. [backgroundImageView setContentMode:UIViewContentModeScaleAspectFill];
  86. }
  87. if (self.statusBarStyle) {
  88. [viewController setNeedsStatusBarAppearanceUpdate];
  89. }
  90. [self applyModalOptions:viewController];
  91. }
  92. - (void)applyModalOptions:(UIViewController*)viewController {
  93. if (self.modalPresentationStyle) {
  94. viewController.modalPresentationStyle = [RCTConvert UIModalPresentationStyle:self.modalPresentationStyle];
  95. }
  96. if (self.modalTransitionStyle) {
  97. viewController.modalTransitionStyle = [RCTConvert UIModalTransitionStyle:self.modalTransitionStyle];
  98. }
  99. }
  100. - (UIInterfaceOrientationMask)supportedOrientations {
  101. NSArray* orientationsArray = [self.orientation isKindOfClass:[NSString class]] ? @[self.orientation] : self.orientation;
  102. NSUInteger supportedOrientationsMask = 0;
  103. if (!orientationsArray || [self.orientation isEqual:@"default"]) {
  104. return [[UIApplication sharedApplication] supportedInterfaceOrientationsForWindow:[[UIApplication sharedApplication] keyWindow]];
  105. } else {
  106. for (NSString* orientation in orientationsArray) {
  107. if ([orientation isEqualToString:@"all"]) {
  108. supportedOrientationsMask = UIInterfaceOrientationMaskAll;
  109. break;
  110. }
  111. if ([orientation isEqualToString:@"landscape"]) {
  112. supportedOrientationsMask = (supportedOrientationsMask | UIInterfaceOrientationMaskLandscape);
  113. }
  114. if ([orientation isEqualToString:@"portrait"]) {
  115. supportedOrientationsMask = (supportedOrientationsMask | UIInterfaceOrientationMaskPortrait);
  116. }
  117. if ([orientation isEqualToString:@"upsideDown"]) {
  118. supportedOrientationsMask = (supportedOrientationsMask | UIInterfaceOrientationMaskPortraitUpsideDown);
  119. }
  120. }
  121. }
  122. return supportedOrientationsMask;
  123. }
  124. @end