react-native-navigation的迁移库

RNNBasePresenter.m 6.4KB

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