react-native-navigation的迁移库

RNNBasePresenter.m 9.2KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201
  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 "RNNDotIndicatorPresenter.h"
  8. #import "RCTConvert+Modal.h"
  9. @interface RNNBasePresenter ()
  10. @property(nonatomic, strong) RNNDotIndicatorPresenter* dotIndicatorPresenter;
  11. @end
  12. @implementation RNNBasePresenter
  13. -(instancetype)initWithDefaultOptions:(RNNNavigationOptions *)defaultOptions {
  14. self = [super init];
  15. _defaultOptions = defaultOptions;
  16. self.dotIndicatorPresenter = [[RNNDotIndicatorPresenter alloc] initWithDefaultOptions:_defaultOptions];
  17. return self;
  18. }
  19. - (void)bindViewController:(UIViewController *)boundViewController {
  20. self.boundComponentId = boundViewController.layoutInfo.componentId;
  21. _boundViewController = boundViewController;
  22. }
  23. - (void)setDefaultOptions:(RNNNavigationOptions *)defaultOptions {
  24. _defaultOptions = defaultOptions;
  25. }
  26. - (void)applyOptionsOnInit:(RNNNavigationOptions *)initialOptions {
  27. UIViewController* viewController = self.boundViewController;
  28. RNNNavigationOptions *withDefault = [initialOptions withDefault:[self defaultOptions]];
  29. [viewController setModalPresentationStyle:[RCTConvert UIModalPresentationStyle:[withDefault.modalPresentationStyle getWithDefaultValue:@"default"]]];
  30. [viewController setModalTransitionStyle:[RCTConvert UIModalTransitionStyle:[withDefault.modalTransitionStyle getWithDefaultValue:@"coverVertical"]]];
  31. if (@available(iOS 13.0, *)) {
  32. viewController.modalInPresentation = ![withDefault.modal.swipeToDismiss getWithDefaultValue:YES];
  33. }
  34. }
  35. - (void)applyOptionsOnViewDidLayoutSubviews:(RNNNavigationOptions *)options {
  36. }
  37. - (void)applyOptionsOnWillMoveToParentViewController:(RNNNavigationOptions *)options {
  38. UIViewController *viewController = self.boundViewController;
  39. RNNNavigationOptions * withDefault = [options withDefault:_defaultOptions];
  40. if (withDefault.bottomTab.text.hasValue) {
  41. UITabBarItem *tabItem = [RNNTabBarItemCreator updateTabBarItem:viewController.tabBarItem bottomTabOptions:withDefault.bottomTab];
  42. viewController.tabBarItem = tabItem;
  43. }
  44. if (withDefault.bottomTab.icon.hasValue) {
  45. UITabBarItem *tabItem = [RNNTabBarItemCreator updateTabBarItem:viewController.tabBarItem bottomTabOptions:withDefault.bottomTab];
  46. viewController.tabBarItem = tabItem;
  47. }
  48. if (withDefault.bottomTab.selectedIcon.hasValue) {
  49. UITabBarItem *tabItem = [RNNTabBarItemCreator updateTabBarItem:viewController.tabBarItem bottomTabOptions:withDefault.bottomTab];
  50. viewController.tabBarItem = tabItem;
  51. }
  52. if (withDefault.bottomTab.badgeColor.hasValue) {
  53. UITabBarItem *tabItem = [RNNTabBarItemCreator updateTabBarItem:viewController.tabBarItem bottomTabOptions:withDefault.bottomTab];
  54. viewController.tabBarItem = tabItem;
  55. }
  56. if (withDefault.bottomTab.textColor.hasValue) {
  57. UITabBarItem *tabItem = [RNNTabBarItemCreator updateTabBarItem:viewController.tabBarItem bottomTabOptions:withDefault.bottomTab];
  58. viewController.tabBarItem = tabItem;
  59. }
  60. if (withDefault.bottomTab.iconColor.hasValue) {
  61. UITabBarItem *tabItem = [RNNTabBarItemCreator updateTabBarItem:viewController.tabBarItem bottomTabOptions:withDefault.bottomTab];
  62. viewController.tabBarItem = tabItem;
  63. }
  64. if (withDefault.bottomTab.selectedTextColor.hasValue) {
  65. UITabBarItem *tabItem = [RNNTabBarItemCreator updateTabBarItem:viewController.tabBarItem bottomTabOptions:withDefault.bottomTab];
  66. viewController.tabBarItem = tabItem;
  67. }
  68. if (withDefault.bottomTab.selectedIconColor.hasValue) {
  69. UITabBarItem *tabItem = [RNNTabBarItemCreator updateTabBarItem:viewController.tabBarItem bottomTabOptions:withDefault.bottomTab];
  70. viewController.tabBarItem = tabItem;
  71. }
  72. }
  73. - (void)applyOptions:(RNNNavigationOptions *)options {
  74. UIViewController *viewController = self.boundViewController;
  75. RNNNavigationOptions * withDefault = [options withDefault:_defaultOptions];
  76. if (withDefault.bottomTab.badge.hasValue && [viewController.parentViewController isKindOfClass:[UITabBarController class]]) {
  77. [viewController setTabBarItemBadge:withDefault.bottomTab.badge.get];
  78. }
  79. if (withDefault.bottomTab.badgeColor.hasValue && [viewController.parentViewController isKindOfClass:[UITabBarController class]]) {
  80. [viewController setTabBarItemBadgeColor:withDefault.bottomTab.badgeColor.get];
  81. }
  82. }
  83. - (void)mergeOptions:(RNNNavigationOptions *)options resolvedOptions:(RNNNavigationOptions *)resolvedOptions {
  84. UIViewController *viewController = self.boundViewController;
  85. if (options.bottomTab.badge.hasValue && [viewController.parentViewController isKindOfClass:[UITabBarController class]]) {
  86. [viewController setTabBarItemBadge:options.bottomTab.badge.get];
  87. }
  88. if (options.bottomTab.badgeColor.hasValue && [viewController.parentViewController isKindOfClass:[UITabBarController class]]) {
  89. [viewController setTabBarItemBadgeColor:options.bottomTab.badgeColor.get];
  90. }
  91. if ([options.bottomTab.dotIndicator hasValue] && [viewController.parentViewController isKindOfClass:[UITabBarController class]]) {
  92. [[self dotIndicatorPresenter] apply:viewController:options.bottomTab.dotIndicator];
  93. }
  94. if (options.bottomTab.text.hasValue) {
  95. RNNNavigationOptions *buttonsResolvedOptions = (RNNNavigationOptions *) [resolvedOptions overrideOptions:options];
  96. UITabBarItem *tabItem = [RNNTabBarItemCreator updateTabBarItem:viewController.tabBarItem bottomTabOptions:buttonsResolvedOptions.bottomTab];
  97. viewController.tabBarItem = tabItem;
  98. }
  99. if (options.bottomTab.icon.hasValue) {
  100. RNNNavigationOptions *buttonsResolvedOptions = (RNNNavigationOptions *) [resolvedOptions overrideOptions:options];
  101. UITabBarItem *tabItem = [RNNTabBarItemCreator updateTabBarItem:viewController.tabBarItem bottomTabOptions:buttonsResolvedOptions.bottomTab];
  102. viewController.tabBarItem = tabItem;
  103. }
  104. if (options.bottomTab.selectedIcon.hasValue) {
  105. RNNNavigationOptions *buttonsResolvedOptions = (RNNNavigationOptions *) [resolvedOptions overrideOptions:options];
  106. UITabBarItem *tabItem = [RNNTabBarItemCreator updateTabBarItem:viewController.tabBarItem bottomTabOptions:buttonsResolvedOptions.bottomTab];
  107. viewController.tabBarItem = tabItem;
  108. }
  109. if (options.bottomTab.textColor.hasValue) {
  110. RNNNavigationOptions *buttonsResolvedOptions = (RNNNavigationOptions *) [resolvedOptions overrideOptions:options];
  111. UITabBarItem *tabItem = [RNNTabBarItemCreator updateTabBarItem:viewController.tabBarItem bottomTabOptions:buttonsResolvedOptions.bottomTab];
  112. viewController.tabBarItem = tabItem;
  113. }
  114. if (options.bottomTab.selectedTextColor.hasValue) {
  115. RNNNavigationOptions *buttonsResolvedOptions = (RNNNavigationOptions *) [resolvedOptions overrideOptions:options];
  116. UITabBarItem *tabItem = [RNNTabBarItemCreator updateTabBarItem:viewController.tabBarItem bottomTabOptions:buttonsResolvedOptions.bottomTab];
  117. viewController.tabBarItem = tabItem;
  118. }
  119. if (options.bottomTab.iconColor.hasValue) {
  120. RNNNavigationOptions *buttonsResolvedOptions = (RNNNavigationOptions *) [resolvedOptions overrideOptions:options];
  121. UITabBarItem *tabItem = [RNNTabBarItemCreator updateTabBarItem:viewController.tabBarItem bottomTabOptions:buttonsResolvedOptions.bottomTab];
  122. viewController.tabBarItem = tabItem;
  123. }
  124. if (options.bottomTab.selectedIconColor.hasValue) {
  125. RNNNavigationOptions *buttonsResolvedOptions = (RNNNavigationOptions *) [resolvedOptions overrideOptions:options];
  126. UITabBarItem *tabItem = [RNNTabBarItemCreator updateTabBarItem:viewController.tabBarItem bottomTabOptions:buttonsResolvedOptions.bottomTab];
  127. viewController.tabBarItem = tabItem;
  128. }
  129. }
  130. - (void)renderComponents:(RNNNavigationOptions *)options perform:(RNNReactViewReadyCompletionBlock)readyBlock {
  131. if (readyBlock) {
  132. readyBlock();
  133. readyBlock = nil;
  134. }
  135. }
  136. - (void)viewDidLayoutSubviews {
  137. }
  138. - (void)applyDotIndicator:(UIViewController *)child {
  139. [[self dotIndicatorPresenter] apply:child:[child resolveOptions].bottomTab.dotIndicator];
  140. }
  141. - (UIStatusBarStyle)getStatusBarStyle:(RNNNavigationOptions *)resolvedOptions {
  142. RNNNavigationOptions *withDefault = [resolvedOptions withDefault:[self defaultOptions]];
  143. if ([[withDefault.statusBar.style getWithDefaultValue:@"default"] isEqualToString:@"light"]) {
  144. return UIStatusBarStyleLightContent;
  145. } else {
  146. return UIStatusBarStyleDefault;
  147. }
  148. }
  149. - (UIInterfaceOrientationMask)getOrientation:(RNNNavigationOptions *)options {
  150. return [options withDefault:[self defaultOptions]].layout.supportedOrientations;
  151. }
  152. - (BOOL)isStatusBarVisibility:(UINavigationController *)stack resolvedOptions:(RNNNavigationOptions *)resolvedOptions {
  153. RNNNavigationOptions *withDefault = [resolvedOptions withDefault:[self defaultOptions]];
  154. if (withDefault.statusBar.visible.hasValue) {
  155. return ![withDefault.statusBar.visible get];
  156. } else if ([withDefault.statusBar.hideWithTopBar getWithDefaultValue:NO]) {
  157. return stack.isNavigationBarHidden;
  158. }
  159. return NO;
  160. }
  161. @end