react-native-navigation的迁移库

RNNBasePresenter.m 7.7KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165
  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. @property(nonatomic, strong) RNNNavigationOptions* defaultOptions;
  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 <RNNLayoutProtocol> *)boundViewController {
  20. self.boundComponentId = boundViewController.layoutInfo.componentId;
  21. _boundViewController = boundViewController;
  22. }
  23. - (void)applyOptionsOnInit:(RNNNavigationOptions *)initialOptions {
  24. }
  25. - (void)applyOptionsOnViewDidLayoutSubviews:(RNNNavigationOptions *)options {
  26. }
  27. - (void)applyOptionsOnWillMoveToParentViewController:(RNNNavigationOptions *)options {
  28. UIViewController *viewController = self.boundViewController;
  29. RNNNavigationOptions * withDefault = [options withDefault:_defaultOptions];
  30. if (withDefault.bottomTab.text.hasValue) {
  31. UITabBarItem *tabItem = [RNNTabBarItemCreator updateTabBarItem:viewController.tabBarItem bottomTabOptions:withDefault.bottomTab];
  32. viewController.tabBarItem = tabItem;
  33. }
  34. if (withDefault.bottomTab.icon.hasValue) {
  35. UITabBarItem *tabItem = [RNNTabBarItemCreator updateTabBarItem:viewController.tabBarItem bottomTabOptions:withDefault.bottomTab];
  36. viewController.tabBarItem = tabItem;
  37. }
  38. if (withDefault.bottomTab.selectedIcon.hasValue) {
  39. UITabBarItem *tabItem = [RNNTabBarItemCreator updateTabBarItem:viewController.tabBarItem bottomTabOptions:withDefault.bottomTab];
  40. viewController.tabBarItem = tabItem;
  41. }
  42. if (withDefault.bottomTab.badgeColor.hasValue) {
  43. UITabBarItem *tabItem = [RNNTabBarItemCreator updateTabBarItem:viewController.tabBarItem bottomTabOptions:withDefault.bottomTab];
  44. viewController.tabBarItem = tabItem;
  45. }
  46. if (withDefault.bottomTab.textColor.hasValue) {
  47. UITabBarItem *tabItem = [RNNTabBarItemCreator updateTabBarItem:viewController.tabBarItem bottomTabOptions:withDefault.bottomTab];
  48. viewController.tabBarItem = tabItem;
  49. }
  50. if (withDefault.bottomTab.iconColor.hasValue) {
  51. UITabBarItem *tabItem = [RNNTabBarItemCreator updateTabBarItem:viewController.tabBarItem bottomTabOptions:withDefault.bottomTab];
  52. viewController.tabBarItem = tabItem;
  53. }
  54. if (withDefault.bottomTab.selectedTextColor.hasValue) {
  55. UITabBarItem *tabItem = [RNNTabBarItemCreator updateTabBarItem:viewController.tabBarItem bottomTabOptions:withDefault.bottomTab];
  56. viewController.tabBarItem = tabItem;
  57. }
  58. if (withDefault.bottomTab.selectedIconColor.hasValue) {
  59. UITabBarItem *tabItem = [RNNTabBarItemCreator updateTabBarItem:viewController.tabBarItem bottomTabOptions:withDefault.bottomTab];
  60. viewController.tabBarItem = tabItem;
  61. }
  62. }
  63. - (void)applyOptions:(RNNNavigationOptions *)options {
  64. UIViewController *viewController = self.boundViewController;
  65. RNNNavigationOptions * withDefault = [options withDefault:_defaultOptions];
  66. if (withDefault.bottomTab.badge.hasValue && [viewController.parentViewController isKindOfClass:[UITabBarController class]]) {
  67. [viewController rnn_setTabBarItemBadge:withDefault.bottomTab.badge.get];
  68. }
  69. if (withDefault.bottomTab.badgeColor.hasValue && [viewController.parentViewController isKindOfClass:[UITabBarController class]]) {
  70. [viewController rnn_setTabBarItemBadgeColor:withDefault.bottomTab.badgeColor.get];
  71. }
  72. }
  73. - (void)mergeOptions:(RNNNavigationOptions *)newOptions currentOptions:(RNNNavigationOptions *)currentOptions {
  74. UIViewController *viewController = self.boundViewController;
  75. if (newOptions.bottomTab.badge.hasValue && [viewController.parentViewController isKindOfClass:[UITabBarController class]]) {
  76. [viewController rnn_setTabBarItemBadge:newOptions.bottomTab.badge.get];
  77. }
  78. if (newOptions.bottomTab.badgeColor.hasValue && [viewController.parentViewController isKindOfClass:[UITabBarController class]]) {
  79. [viewController rnn_setTabBarItemBadgeColor:newOptions.bottomTab.badgeColor.get];
  80. }
  81. if ([newOptions.bottomTab.dotIndicator hasValue] && [viewController.parentViewController isKindOfClass:[UITabBarController class]]) {
  82. [[self dotIndicatorPresenter] apply:viewController:newOptions.bottomTab.dotIndicator];
  83. }
  84. if (newOptions.bottomTab.text.hasValue) {
  85. RNNNavigationOptions *buttonsResolvedOptions = (RNNNavigationOptions *) [currentOptions overrideOptions:newOptions];
  86. UITabBarItem *tabItem = [RNNTabBarItemCreator updateTabBarItem:viewController.tabBarItem bottomTabOptions:buttonsResolvedOptions.bottomTab];
  87. viewController.tabBarItem = tabItem;
  88. }
  89. if (newOptions.bottomTab.icon.hasValue) {
  90. RNNNavigationOptions *buttonsResolvedOptions = (RNNNavigationOptions *) [currentOptions overrideOptions:newOptions];
  91. UITabBarItem *tabItem = [RNNTabBarItemCreator updateTabBarItem:viewController.tabBarItem bottomTabOptions:buttonsResolvedOptions.bottomTab];
  92. viewController.tabBarItem = tabItem;
  93. }
  94. if (newOptions.bottomTab.selectedIcon.hasValue) {
  95. RNNNavigationOptions *buttonsResolvedOptions = (RNNNavigationOptions *) [currentOptions overrideOptions:newOptions];
  96. UITabBarItem *tabItem = [RNNTabBarItemCreator updateTabBarItem:viewController.tabBarItem bottomTabOptions:buttonsResolvedOptions.bottomTab];
  97. viewController.tabBarItem = tabItem;
  98. }
  99. if (newOptions.bottomTab.textColor.hasValue) {
  100. RNNNavigationOptions *buttonsResolvedOptions = (RNNNavigationOptions *) [currentOptions overrideOptions:newOptions];
  101. UITabBarItem *tabItem = [RNNTabBarItemCreator updateTabBarItem:viewController.tabBarItem bottomTabOptions:buttonsResolvedOptions.bottomTab];
  102. viewController.tabBarItem = tabItem;
  103. }
  104. if (newOptions.bottomTab.selectedTextColor.hasValue) {
  105. RNNNavigationOptions *buttonsResolvedOptions = (RNNNavigationOptions *) [currentOptions overrideOptions:newOptions];
  106. UITabBarItem *tabItem = [RNNTabBarItemCreator updateTabBarItem:viewController.tabBarItem bottomTabOptions:buttonsResolvedOptions.bottomTab];
  107. viewController.tabBarItem = tabItem;
  108. }
  109. if (newOptions.bottomTab.iconColor.hasValue) {
  110. RNNNavigationOptions *buttonsResolvedOptions = (RNNNavigationOptions *) [currentOptions overrideOptions:newOptions];
  111. UITabBarItem *tabItem = [RNNTabBarItemCreator updateTabBarItem:viewController.tabBarItem bottomTabOptions:buttonsResolvedOptions.bottomTab];
  112. viewController.tabBarItem = tabItem;
  113. }
  114. if (newOptions.bottomTab.selectedIconColor.hasValue) {
  115. RNNNavigationOptions *buttonsResolvedOptions = (RNNNavigationOptions *) [currentOptions overrideOptions:newOptions];
  116. UITabBarItem *tabItem = [RNNTabBarItemCreator updateTabBarItem:viewController.tabBarItem bottomTabOptions:buttonsResolvedOptions.bottomTab];
  117. viewController.tabBarItem = tabItem;
  118. }
  119. }
  120. - (void)renderComponents:(RNNNavigationOptions *)options perform:(RNNReactViewReadyCompletionBlock)readyBlock {
  121. if (readyBlock) {
  122. readyBlock();
  123. readyBlock = nil;
  124. }
  125. }
  126. - (void)viewDidLayoutSubviews {
  127. }
  128. - (void)applyDotIndicator:(UIViewController *)child {
  129. [[self dotIndicatorPresenter] apply:child:[child resolveOptions].bottomTab.dotIndicator];
  130. }
  131. @end