react-native-navigation的迁移库

RNNNavigationOptions.m 5.3KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131
  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.statusBar applyOn:viewController];
  42. [self applyOtherOptionsOn:viewController];
  43. [viewController optionsUpdated];
  44. }
  45. - (void)applyOtherOptionsOn:(UIViewController*)viewController {
  46. if (self.popGesture) {
  47. viewController.navigationController.interactivePopGestureRecognizer.enabled = [self.popGesture boolValue];
  48. }
  49. if (self.screenBackgroundColor) {
  50. UIColor* screenColor = [RCTConvert UIColor:self.screenBackgroundColor];
  51. viewController.view.backgroundColor = screenColor;
  52. }
  53. if (self.backgroundImage) {
  54. UIImageView* backgroundImageView = (viewController.view.subviews.count > 0) ? viewController.view.subviews[0] : nil;
  55. if (![backgroundImageView isKindOfClass:[UIImageView class]]) {
  56. backgroundImageView = [[UIImageView alloc] initWithFrame:viewController.view.bounds];
  57. [viewController.view insertSubview:backgroundImageView atIndex:0];
  58. }
  59. backgroundImageView.layer.masksToBounds = YES;
  60. backgroundImageView.image = [self.backgroundImage isKindOfClass:[UIImage class]] ? (UIImage*)self.backgroundImage : [RCTConvert UIImage:self.backgroundImage];
  61. [backgroundImageView setContentMode:UIViewContentModeScaleAspectFill];
  62. }
  63. if (self.rootBackgroundImage) {
  64. UIImageView* backgroundImageView = (viewController.navigationController.view.subviews.count > 0) ? viewController.navigationController.view.subviews[0] : nil;
  65. if (![backgroundImageView isKindOfClass:[UIImageView class]]) {
  66. backgroundImageView = [[UIImageView alloc] initWithFrame:viewController.view.bounds];
  67. [viewController.navigationController.view insertSubview:backgroundImageView atIndex:0];
  68. }
  69. backgroundImageView.layer.masksToBounds = YES;
  70. backgroundImageView.image = [self.rootBackgroundImage isKindOfClass:[UIImage class]] ? (UIImage*)self.rootBackgroundImage : [RCTConvert UIImage:self.rootBackgroundImage];
  71. [backgroundImageView setContentMode:UIViewContentModeScaleAspectFill];
  72. }
  73. [self applyModalOptions:viewController];
  74. }
  75. - (void)applyModalOptions:(UIViewController*)viewController {
  76. if (self.modalPresentationStyle) {
  77. viewController.modalPresentationStyle = [RCTConvert UIModalPresentationStyle:self.modalPresentationStyle];
  78. }
  79. if (self.modalTransitionStyle) {
  80. viewController.modalTransitionStyle = [RCTConvert UIModalTransitionStyle:self.modalTransitionStyle];
  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