react-native-navigation的迁移库

RNNBasePresenter.m 6.3KB

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