react-native-navigation的迁移库

RNNBasePresenter.m 6.7KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150
  1. #import "RNNBasePresenter.h"
  2. #import "UIViewController+RNNOptions.h"
  3. #import "RNNTabBarItemCreator.h"
  4. #import "RNNReactComponentRegistry.h"
  5. #import "UIViewController+LayoutProtocol.h"
  6. @interface RNNBasePresenter ()
  7. @property (nonatomic, strong) RNNReactComponentRegistry* componentRegistry;
  8. @end
  9. @implementation RNNBasePresenter
  10. - (instancetype)initWithComponentRegistry:(RNNReactComponentRegistry *)componentRegistry {
  11. self = [super init];
  12. self.componentRegistry = componentRegistry;
  13. return self;
  14. }
  15. - (void)bindViewController:(UIViewController<RNNLayoutProtocol> *)bindedViewController {
  16. self.bindedComponentId = bindedViewController.layoutInfo.componentId;
  17. _bindedViewController = bindedViewController;
  18. }
  19. - (void)applyOptionsOnInit:(RNNNavigationOptions *)initialOptions {
  20. }
  21. - (void)applyOptionsOnSetViewControllers:(RNNNavigationOptions *)options {
  22. }
  23. - (void)applyOptionsOnWillMoveToParentViewController:(RNNNavigationOptions *)options {
  24. UIViewController* viewController = self.bindedViewController;
  25. if (options.bottomTab.text.hasValue) {
  26. UITabBarItem* tabItem = [RNNTabBarItemCreator updateTabBarItem:viewController.tabBarItem bottomTabOptions:options.bottomTab];
  27. viewController.tabBarItem = tabItem;
  28. }
  29. if (options.bottomTab.icon.hasValue) {
  30. UITabBarItem* tabItem = [RNNTabBarItemCreator updateTabBarItem:viewController.tabBarItem bottomTabOptions:options.bottomTab];
  31. viewController.tabBarItem = tabItem;
  32. }
  33. if (options.bottomTab.selectedIcon.hasValue) {
  34. UITabBarItem* tabItem = [RNNTabBarItemCreator updateTabBarItem:viewController.tabBarItem bottomTabOptions:options.bottomTab];
  35. viewController.tabBarItem = tabItem;
  36. }
  37. if (options.bottomTab.badgeColor.hasValue) {
  38. UITabBarItem* tabItem = [RNNTabBarItemCreator updateTabBarItem:viewController.tabBarItem bottomTabOptions:options.bottomTab];
  39. viewController.tabBarItem = tabItem;
  40. }
  41. if (options.bottomTab.textColor.hasValue) {
  42. UITabBarItem* tabItem = [RNNTabBarItemCreator updateTabBarItem:viewController.tabBarItem bottomTabOptions:options.bottomTab];
  43. viewController.tabBarItem = tabItem;
  44. }
  45. if (options.bottomTab.iconColor.hasValue) {
  46. UITabBarItem* tabItem = [RNNTabBarItemCreator updateTabBarItem:viewController.tabBarItem bottomTabOptions:options.bottomTab];
  47. viewController.tabBarItem = tabItem;
  48. }
  49. if (options.bottomTab.selectedTextColor.hasValue) {
  50. UITabBarItem* tabItem = [RNNTabBarItemCreator updateTabBarItem:viewController.tabBarItem bottomTabOptions:options.bottomTab];
  51. viewController.tabBarItem = tabItem;
  52. }
  53. if (options.bottomTab.selectedIconColor.hasValue) {
  54. UITabBarItem* tabItem = [RNNTabBarItemCreator updateTabBarItem:viewController.tabBarItem bottomTabOptions:options.bottomTab];
  55. viewController.tabBarItem = tabItem;
  56. }
  57. }
  58. - (void)applyOptions:(RNNNavigationOptions *)options {
  59. UIViewController* viewController = self.bindedViewController;
  60. if (options.bottomTab.badge.hasValue && [viewController.parentViewController isKindOfClass:[UITabBarController class]]) {
  61. [viewController rnn_setTabBarItemBadge:options.bottomTab.badge.get];
  62. }
  63. if (options.bottomTab.badgeColor.hasValue && [viewController.parentViewController isKindOfClass:[UITabBarController class]]) {
  64. [viewController rnn_setTabBarItemBadgeColor:options.bottomTab.badgeColor.get];
  65. }
  66. }
  67. - (void)mergeOptions:(RNNNavigationOptions *)newOptions currentOptions:(RNNNavigationOptions *)currentOptions defaultOptions:(RNNNavigationOptions *)defaultOptions {
  68. UIViewController* viewController = self.bindedViewController;
  69. if (newOptions.bottomTab.badge.hasValue && [viewController.parentViewController isKindOfClass:[UITabBarController class]]) {
  70. [viewController rnn_setTabBarItemBadge:newOptions.bottomTab.badge.get];
  71. }
  72. if (newOptions.bottomTab.badgeColor.hasValue && [viewController.parentViewController isKindOfClass:[UITabBarController class]]) {
  73. [viewController rnn_setTabBarItemBadgeColor:newOptions.bottomTab.badgeColor.get];
  74. }
  75. if (newOptions.bottomTab.text.hasValue) {
  76. RNNNavigationOptions* buttonsResolvedOptions = [(RNNNavigationOptions *)[currentOptions overrideOptions:newOptions] withDefault:defaultOptions];
  77. UITabBarItem* tabItem = [RNNTabBarItemCreator updateTabBarItem:viewController.tabBarItem bottomTabOptions:buttonsResolvedOptions.bottomTab];
  78. viewController.tabBarItem = tabItem;
  79. }
  80. if (newOptions.bottomTab.icon.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.selectedIcon.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.textColor.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.selectedTextColor.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.iconColor.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.selectedIconColor.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. }
  111. - (void)renderComponents:(RNNNavigationOptions *)options perform:(RNNReactViewReadyCompletionBlock)readyBlock {
  112. if (readyBlock) {
  113. readyBlock();
  114. readyBlock = nil;
  115. }
  116. }
  117. @end