react-native-navigation的迁移库

RNNNavigationOptions.m 4.1KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104
  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 mergeOptions:_defaultOptions overrideOptions:NO];
  37. [self.topBar applyOn:viewController];
  38. [self.bottomTabs applyOn:viewController];
  39. [self.topTab applyOn:viewController];
  40. [self.bottomTab applyOn:viewController];
  41. [self.sideMenu applyOn:viewController];
  42. [self.overlay applyOn:viewController];
  43. [self.statusBar applyOn:viewController];
  44. [self.layout applyOn:viewController];
  45. [self applyOtherOptionsOn:viewController];
  46. [viewController optionsUpdated];
  47. }
  48. - (void)applyOtherOptionsOn:(UIViewController*)viewController {
  49. if (self.popGesture) {
  50. viewController.navigationController.interactivePopGestureRecognizer.enabled = [self.popGesture boolValue];
  51. }
  52. if (self.backgroundImage) {
  53. UIImageView* backgroundImageView = (viewController.view.subviews.count > 0) ? viewController.view.subviews[0] : nil;
  54. if (![backgroundImageView isKindOfClass:[UIImageView class]]) {
  55. backgroundImageView = [[UIImageView alloc] initWithFrame:viewController.view.bounds];
  56. [viewController.view insertSubview:backgroundImageView atIndex:0];
  57. }
  58. backgroundImageView.layer.masksToBounds = YES;
  59. backgroundImageView.image = [self.backgroundImage isKindOfClass:[UIImage class]] ? (UIImage*)self.backgroundImage : [RCTConvert UIImage:self.backgroundImage];
  60. [backgroundImageView setContentMode:UIViewContentModeScaleAspectFill];
  61. }
  62. if (self.rootBackgroundImage) {
  63. UIImageView* backgroundImageView = (viewController.navigationController.view.subviews.count > 0) ? viewController.navigationController.view.subviews[0] : nil;
  64. if (![backgroundImageView isKindOfClass:[UIImageView class]]) {
  65. backgroundImageView = [[UIImageView alloc] initWithFrame:viewController.view.bounds];
  66. [viewController.navigationController.view insertSubview:backgroundImageView atIndex:0];
  67. }
  68. backgroundImageView.layer.masksToBounds = YES;
  69. backgroundImageView.image = [self.rootBackgroundImage isKindOfClass:[UIImage class]] ? (UIImage*)self.rootBackgroundImage : [RCTConvert UIImage:self.rootBackgroundImage];
  70. [backgroundImageView setContentMode:UIViewContentModeScaleAspectFill];
  71. }
  72. [self applyModalOptions:viewController];
  73. }
  74. - (void)applyModalOptions:(UIViewController*)viewController {
  75. if (self.modalPresentationStyle) {
  76. viewController.modalPresentationStyle = [RCTConvert UIModalPresentationStyle:self.modalPresentationStyle];
  77. [viewController.view setBackgroundColor:[UIColor clearColor]];
  78. }
  79. if (self.modalTransitionStyle) {
  80. viewController.modalTransitionStyle = [RCTConvert UIModalTransitionStyle:self.modalTransitionStyle];
  81. }
  82. }
  83. @end