react-native-navigation的迁移库

RNNBasePresenter.m 6.3KB

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