react-native-navigation的迁移库

RNNNavigationOptions.m 4.0KB

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