react-native-navigation的迁移库

RNNBasePresenter.m 9.3KB

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