react-native-navigation的迁移库

RNNNavigationOptions.m 5.3KB

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