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