react-native-navigation的迁移库

RNNBasePresenter.m 8.7KB

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