react-native-navigation的迁移库

RNNBasePresenter.m 7.5KB

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