react-native-navigation的迁移库

RNNNavigationOptions.m 5.0KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127
  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 RNNNavigationOptions
  26. -(void)applyOn:(UIViewController<RNNRootViewProtocol> *)viewController {
  27. [self.topBar applyOn:viewController];
  28. [self.bottomTabs applyOn:viewController];
  29. [self.topTab applyOn:viewController];
  30. [self.bottomTab applyOn:viewController];
  31. [self.sideMenu applyOn:viewController];
  32. [self.overlay applyOn:viewController];
  33. [self applyOtherOptionsOn:viewController];
  34. [viewController optionsUpdated];
  35. }
  36. - (void)applyOtherOptionsOn:(UIViewController*)viewController {
  37. if (self.popGesture) {
  38. viewController.navigationController.interactivePopGestureRecognizer.enabled = [self.popGesture boolValue];
  39. }
  40. if (self.screenBackgroundColor) {
  41. UIColor* screenColor = [RCTConvert UIColor:self.screenBackgroundColor];
  42. viewController.view.backgroundColor = screenColor;
  43. }
  44. if (self.statusBarBlur) {
  45. UIView* curBlurView = [viewController.view viewWithTag:BLUR_STATUS_TAG];
  46. if ([self.statusBarBlur boolValue]) {
  47. if (!curBlurView) {
  48. UIVisualEffectView *blur = [[UIVisualEffectView alloc] initWithEffect:[UIBlurEffect effectWithStyle:UIBlurEffectStyleLight]];
  49. blur.frame = [[UIApplication sharedApplication] statusBarFrame];
  50. blur.tag = BLUR_STATUS_TAG;
  51. [viewController.view insertSubview:blur atIndex:0];
  52. }
  53. } else {
  54. if (curBlurView) {
  55. [curBlurView removeFromSuperview];
  56. }
  57. }
  58. }
  59. if (self.backgroundImage) {
  60. UIImageView* backgroundImageView = (viewController.view.subviews.count > 0) ? viewController.view.subviews[0] : nil;
  61. if (![backgroundImageView isKindOfClass:[UIImageView class]]) {
  62. backgroundImageView = [[UIImageView alloc] initWithFrame:viewController.view.bounds];
  63. [viewController.view insertSubview:backgroundImageView atIndex:0];
  64. }
  65. backgroundImageView.layer.masksToBounds = YES;
  66. backgroundImageView.image = [self.backgroundImage isKindOfClass:[UIImage class]] ? (UIImage*)self.backgroundImage : [RCTConvert UIImage:self.backgroundImage];
  67. [backgroundImageView setContentMode:UIViewContentModeScaleAspectFill];
  68. }
  69. if (self.rootBackgroundImage) {
  70. UIImageView* backgroundImageView = (viewController.navigationController.view.subviews.count > 0) ? viewController.navigationController.view.subviews[0] : nil;
  71. if (![backgroundImageView isKindOfClass:[UIImageView class]]) {
  72. backgroundImageView = [[UIImageView alloc] initWithFrame:viewController.view.bounds];
  73. [viewController.navigationController.view insertSubview:backgroundImageView atIndex:0];
  74. }
  75. backgroundImageView.layer.masksToBounds = YES;
  76. backgroundImageView.image = [self.rootBackgroundImage isKindOfClass:[UIImage class]] ? (UIImage*)self.rootBackgroundImage : [RCTConvert UIImage:self.rootBackgroundImage];
  77. [backgroundImageView setContentMode:UIViewContentModeScaleAspectFill];
  78. }
  79. if (self.modalPresentationStyle) {
  80. viewController.modalPresentationStyle = [RCTConvert UIModalPresentationStyle:self.modalPresentationStyle];
  81. }
  82. }
  83. - (UIInterfaceOrientationMask)supportedOrientations {
  84. NSArray* orientationsArray = [self.orientation isKindOfClass:[NSString class]] ? @[self.orientation] : self.orientation;
  85. NSUInteger supportedOrientationsMask = 0;
  86. if (!orientationsArray || [self.orientation isEqual:@"default"]) {
  87. return [[UIApplication sharedApplication] supportedInterfaceOrientationsForWindow:[[UIApplication sharedApplication] keyWindow]];
  88. } else {
  89. for (NSString* orientation in orientationsArray) {
  90. if ([orientation isEqualToString:@"all"]) {
  91. supportedOrientationsMask = UIInterfaceOrientationMaskAll;
  92. break;
  93. }
  94. if ([orientation isEqualToString:@"landscape"]) {
  95. supportedOrientationsMask = (supportedOrientationsMask | UIInterfaceOrientationMaskLandscape);
  96. }
  97. if ([orientation isEqualToString:@"portrait"]) {
  98. supportedOrientationsMask = (supportedOrientationsMask | UIInterfaceOrientationMaskPortrait);
  99. }
  100. if ([orientation isEqualToString:@"upsideDown"]) {
  101. supportedOrientationsMask = (supportedOrientationsMask | UIInterfaceOrientationMaskPortraitUpsideDown);
  102. }
  103. }
  104. }
  105. return supportedOrientationsMask;
  106. }
  107. @end