react-native-navigation的迁移库

RNNBasePresenter.m 6.4KB

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