react-native-navigation的迁移库

RNNBasePresenter.m 4.6KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129
  1. #import "RNNBasePresenter.h"
  2. #import "UIViewController+RNNOptions.h"
  3. #import "RNNTabBarItemCreator.h"
  4. #import "RNNReactComponentRegistry.h"
  5. #import "UIViewController+LayoutProtocol.h"
  6. #import "DotIndicatorOptions.h"
  7. #import "RCTConvert+Modal.h"
  8. #import "BottomTabPresenterCreator.h"
  9. @interface RNNBasePresenter ()
  10. @property(nonatomic, strong) BottomTabPresenter* bottomTabPresenter;
  11. @end
  12. @implementation RNNBasePresenter
  13. - (instancetype)initWithDefaultOptions:(RNNNavigationOptions *)defaultOptions {
  14. self = [super init];
  15. _defaultOptions = defaultOptions;
  16. _bottomTabPresenter = [BottomTabPresenterCreator createWithDefaultOptions:self.defaultOptions];
  17. return self;
  18. }
  19. - (instancetype)initWithComponentRegistry:(RNNReactComponentRegistry *)componentRegistry defaultOptions:(RNNNavigationOptions *)defaultOptions {
  20. self = [self initWithDefaultOptions:defaultOptions];
  21. _componentRegistry = componentRegistry;
  22. return self;
  23. }
  24. - (void)bindViewController:(UIViewController *)boundViewController {
  25. self.boundComponentId = boundViewController.layoutInfo.componentId;
  26. _boundViewController = boundViewController;
  27. _bottomTabPresenter.boundViewController = boundViewController;
  28. }
  29. - (void)setDefaultOptions:(RNNNavigationOptions *)defaultOptions {
  30. _defaultOptions = defaultOptions;
  31. }
  32. - (void)componentDidAppear {
  33. }
  34. - (void)componentDidDisappear {
  35. }
  36. - (void)applyOptionsOnInit:(RNNNavigationOptions *)initialOptions {
  37. UIViewController* viewController = self.boundViewController;
  38. RNNNavigationOptions *withDefault = [initialOptions withDefault:[self defaultOptions]];
  39. [viewController setModalPresentationStyle:[RCTConvert UIModalPresentationStyle:[withDefault.modalPresentationStyle getWithDefaultValue:@"default"]]];
  40. [viewController setModalTransitionStyle:[RCTConvert UIModalTransitionStyle:[withDefault.modalTransitionStyle getWithDefaultValue:@"coverVertical"]]];
  41. if (@available(iOS 13.0, *)) {
  42. viewController.modalInPresentation = ![withDefault.modal.swipeToDismiss getWithDefaultValue:YES];
  43. }
  44. UIApplication.sharedApplication.delegate.window.backgroundColor = [withDefault.window.backgroundColor getWithDefaultValue:nil];
  45. }
  46. - (void)applyOptionsOnViewDidLayoutSubviews:(RNNNavigationOptions *)options {
  47. }
  48. - (void)applyOptionsOnWillMoveToParentViewController:(RNNNavigationOptions *)options {
  49. [_bottomTabPresenter applyOptionsOnWillMoveToParentViewController:options];
  50. }
  51. - (void)applyOptions:(RNNNavigationOptions *)options {
  52. [_bottomTabPresenter applyOptions:options];
  53. }
  54. - (void)mergeOptions:(RNNNavigationOptions *)options resolvedOptions:(RNNNavigationOptions *)resolvedOptions {
  55. UIViewController* viewController = self.boundViewController;
  56. RNNNavigationOptions* withDefault = (RNNNavigationOptions *) [[resolvedOptions withDefault:_defaultOptions] overrideOptions:options];
  57. [_bottomTabPresenter mergeOptions:options resolvedOptions:resolvedOptions];
  58. if (options.window.backgroundColor.hasValue) {
  59. UIApplication.sharedApplication.delegate.window.backgroundColor = withDefault.window.backgroundColor.get;
  60. }
  61. }
  62. - (void)renderComponents:(RNNNavigationOptions *)options perform:(RNNReactViewReadyCompletionBlock)readyBlock {
  63. if (readyBlock) {
  64. readyBlock();
  65. readyBlock = nil;
  66. }
  67. }
  68. - (void)viewDidLayoutSubviews {
  69. }
  70. - (void)applyDotIndicator:(UIViewController *)child {
  71. [_bottomTabPresenter applyDotIndicator:child];
  72. }
  73. - (UIStatusBarStyle)getStatusBarStyle:(RNNNavigationOptions *)resolvedOptions {
  74. RNNNavigationOptions *withDefault = [resolvedOptions withDefault:[self defaultOptions]];
  75. NSString* statusBarStyle = [withDefault.statusBar.style getWithDefaultValue:@"default"];
  76. if ([statusBarStyle isEqualToString:@"light"]) {
  77. return UIStatusBarStyleLightContent;
  78. } else if (@available(iOS 13.0, *)) {
  79. if ([statusBarStyle isEqualToString:@"dark"]) {
  80. return UIStatusBarStyleDarkContent;
  81. } else {
  82. return UIStatusBarStyleDefault;
  83. }
  84. } else {
  85. return UIStatusBarStyleDefault;
  86. }
  87. }
  88. - (UIInterfaceOrientationMask)getOrientation:(RNNNavigationOptions *)options {
  89. return [options withDefault:[self defaultOptions]].layout.supportedOrientations;
  90. }
  91. - (BOOL)isStatusBarVisibility:(UINavigationController *)stack resolvedOptions:(RNNNavigationOptions *)resolvedOptions {
  92. RNNNavigationOptions *withDefault = [resolvedOptions withDefault:[self defaultOptions]];
  93. if (withDefault.statusBar.visible.hasValue) {
  94. return ![withDefault.statusBar.visible get];
  95. } else if ([withDefault.statusBar.hideWithTopBar getWithDefaultValue:NO]) {
  96. return stack.isNavigationBarHidden;
  97. }
  98. return NO;
  99. }
  100. @end