react-native-navigation的迁移库

RNNBasePresenter.m 6.6KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146
  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)applyOptionsOnWillMoveToParentViewController:(RNNNavigationOptions *)options {
  22. UIViewController* viewController = self.bindedViewController;
  23. if (options.bottomTab.text.hasValue) {
  24. UITabBarItem* tabItem = [RNNTabBarItemCreator updateTabBarItem:viewController.tabBarItem bottomTabOptions:options.bottomTab];
  25. viewController.tabBarItem = tabItem;
  26. }
  27. if (options.bottomTab.icon.hasValue) {
  28. UITabBarItem* tabItem = [RNNTabBarItemCreator updateTabBarItem:viewController.tabBarItem bottomTabOptions:options.bottomTab];
  29. viewController.tabBarItem = tabItem;
  30. }
  31. if (options.bottomTab.selectedIcon.hasValue) {
  32. UITabBarItem* tabItem = [RNNTabBarItemCreator updateTabBarItem:viewController.tabBarItem bottomTabOptions:options.bottomTab];
  33. viewController.tabBarItem = tabItem;
  34. }
  35. if (options.bottomTab.badgeColor.hasValue) {
  36. UITabBarItem* tabItem = [RNNTabBarItemCreator updateTabBarItem:viewController.tabBarItem bottomTabOptions:options.bottomTab];
  37. viewController.tabBarItem = tabItem;
  38. }
  39. if (options.bottomTab.textColor.hasValue) {
  40. UITabBarItem* tabItem = [RNNTabBarItemCreator updateTabBarItem:viewController.tabBarItem bottomTabOptions:options.bottomTab];
  41. viewController.tabBarItem = tabItem;
  42. }
  43. if (options.bottomTab.iconColor.hasValue) {
  44. UITabBarItem* tabItem = [RNNTabBarItemCreator updateTabBarItem:viewController.tabBarItem bottomTabOptions:options.bottomTab];
  45. viewController.tabBarItem = tabItem;
  46. }
  47. if (options.bottomTab.selectedTextColor.hasValue) {
  48. UITabBarItem* tabItem = [RNNTabBarItemCreator updateTabBarItem:viewController.tabBarItem bottomTabOptions:options.bottomTab];
  49. viewController.tabBarItem = tabItem;
  50. }
  51. if (options.bottomTab.selectedIconColor.hasValue) {
  52. UITabBarItem* tabItem = [RNNTabBarItemCreator updateTabBarItem:viewController.tabBarItem bottomTabOptions:options.bottomTab];
  53. viewController.tabBarItem = tabItem;
  54. }
  55. }
  56. - (void)applyOptions:(RNNNavigationOptions *)options {
  57. UIViewController* viewController = self.bindedViewController;
  58. if (options.bottomTab.badge.hasValue && [viewController.parentViewController isKindOfClass:[UITabBarController class]]) {
  59. [viewController rnn_setTabBarItemBadge:options.bottomTab.badge.get];
  60. }
  61. if (options.bottomTab.badgeColor.hasValue && [viewController.parentViewController isKindOfClass:[UITabBarController class]]) {
  62. [viewController rnn_setTabBarItemBadgeColor:options.bottomTab.badgeColor.get];
  63. }
  64. }
  65. - (void)mergeOptions:(RNNNavigationOptions *)newOptions currentOptions:(RNNNavigationOptions *)currentOptions defaultOptions:(RNNNavigationOptions *)defaultOptions {
  66. UIViewController* viewController = self.bindedViewController;
  67. if (newOptions.bottomTab.badge.hasValue && [viewController.parentViewController isKindOfClass:[UITabBarController class]]) {
  68. [viewController rnn_setTabBarItemBadge:newOptions.bottomTab.badge.get];
  69. }
  70. if (newOptions.bottomTab.badgeColor.hasValue && [viewController.parentViewController isKindOfClass:[UITabBarController class]]) {
  71. [viewController rnn_setTabBarItemBadgeColor:newOptions.bottomTab.badgeColor.get];
  72. }
  73. if (newOptions.bottomTab.text.hasValue) {
  74. RNNNavigationOptions* buttonsResolvedOptions = [(RNNNavigationOptions *)[currentOptions overrideOptions:newOptions] withDefault:defaultOptions];
  75. UITabBarItem* tabItem = [RNNTabBarItemCreator updateTabBarItem:viewController.tabBarItem bottomTabOptions:buttonsResolvedOptions.bottomTab];
  76. viewController.tabBarItem = tabItem;
  77. }
  78. if (newOptions.bottomTab.icon.hasValue) {
  79. RNNNavigationOptions* buttonsResolvedOptions = [(RNNNavigationOptions *)[currentOptions overrideOptions:newOptions] withDefault:defaultOptions];
  80. UITabBarItem* tabItem = [RNNTabBarItemCreator updateTabBarItem:viewController.tabBarItem bottomTabOptions:buttonsResolvedOptions.bottomTab];
  81. viewController.tabBarItem = tabItem;
  82. }
  83. if (newOptions.bottomTab.selectedIcon.hasValue) {
  84. RNNNavigationOptions* buttonsResolvedOptions = [(RNNNavigationOptions *)[currentOptions overrideOptions:newOptions] withDefault:defaultOptions];
  85. UITabBarItem* tabItem = [RNNTabBarItemCreator updateTabBarItem:viewController.tabBarItem bottomTabOptions:buttonsResolvedOptions.bottomTab];
  86. viewController.tabBarItem = tabItem;
  87. }
  88. if (newOptions.bottomTab.textColor.hasValue) {
  89. RNNNavigationOptions* buttonsResolvedOptions = [(RNNNavigationOptions *)[currentOptions overrideOptions:newOptions] withDefault:defaultOptions];
  90. UITabBarItem* tabItem = [RNNTabBarItemCreator updateTabBarItem:viewController.tabBarItem bottomTabOptions:buttonsResolvedOptions.bottomTab];
  91. viewController.tabBarItem = tabItem;
  92. }
  93. if (newOptions.bottomTab.selectedTextColor.hasValue) {
  94. RNNNavigationOptions* buttonsResolvedOptions = [(RNNNavigationOptions *)[currentOptions overrideOptions:newOptions] withDefault:defaultOptions];
  95. UITabBarItem* tabItem = [RNNTabBarItemCreator updateTabBarItem:viewController.tabBarItem bottomTabOptions:buttonsResolvedOptions.bottomTab];
  96. viewController.tabBarItem = tabItem;
  97. }
  98. if (newOptions.bottomTab.iconColor.hasValue) {
  99. RNNNavigationOptions* buttonsResolvedOptions = [(RNNNavigationOptions *)[currentOptions overrideOptions:newOptions] withDefault:defaultOptions];
  100. UITabBarItem* tabItem = [RNNTabBarItemCreator updateTabBarItem:viewController.tabBarItem bottomTabOptions:buttonsResolvedOptions.bottomTab];
  101. viewController.tabBarItem = tabItem;
  102. }
  103. if (newOptions.bottomTab.selectedIconColor.hasValue) {
  104. RNNNavigationOptions* buttonsResolvedOptions = [(RNNNavigationOptions *)[currentOptions overrideOptions:newOptions] withDefault:defaultOptions];
  105. UITabBarItem* tabItem = [RNNTabBarItemCreator updateTabBarItem:viewController.tabBarItem bottomTabOptions:buttonsResolvedOptions.bottomTab];
  106. viewController.tabBarItem = tabItem;
  107. }
  108. }
  109. - (void)renderComponents:(RNNNavigationOptions *)options perform:(RNNReactViewReadyCompletionBlock)readyBlock {
  110. if (readyBlock) {
  111. readyBlock();
  112. readyBlock = nil;
  113. }
  114. }
  115. @end