react-native-navigation的迁移库

RNNBottomTabPresenter.m 1.7KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. #import "RNNBottomTabPresenter.h"
  2. #import "RNNTabBarItemCreator.h"
  3. #import "UIViewController+RNNOptions.h"
  4. @interface RNNBottomTabPresenter()
  5. @property (nonatomic, weak) id bindedViewController;
  6. @property (nonatomic, retain) RNNNavigationOptions* defaultOptions;
  7. @end
  8. @implementation RNNBottomTabPresenter
  9. - (void)bindViewController:(UIViewController *)viewController {
  10. _bindedViewController = viewController;
  11. }
  12. - (void)applyOptions:(RNNNavigationOptions *)options {
  13. UIViewController* viewController = self.bindedViewController;
  14. if ((options.bottomTab.text.hasValue || options.bottomTab.icon.hasValue || options.bottomTab.selectedIcon.hasValue)) {
  15. RNNNavigationOptions* withDefault = (RNNNavigationOptions *)[[options copy] withDefault:self.defaultOptions];
  16. UITabBarItem* tabItem = [RNNTabBarItemCreator updateTabBarItem:viewController.tabBarItem bottomTabOptions:withDefault.bottomTab];
  17. viewController.tabBarItem = tabItem;
  18. [options.bottomTab.text consume];
  19. [options.bottomTab.icon consume];
  20. [options.bottomTab.selectedIcon consume];
  21. }
  22. if ([viewController.parentViewController isKindOfClass:[UITabBarController class]]) {
  23. [viewController rnn_setTabBarItemBadge:[options.bottomTab.badge getWithDefaultValue:nil]];
  24. }
  25. }
  26. - (void)mergeOptions:(RNNNavigationOptions *)options resolvedOptions:(RNNNavigationOptions *)resolvedOptions {
  27. UIViewController* viewController = self.bindedViewController;
  28. if (options.bottomTab.badge.hasValue && [viewController.parentViewController isKindOfClass:[UITabBarController class]]) {
  29. [viewController rnn_setTabBarItemBadge:options.bottomTab.badge.get];
  30. }
  31. }
  32. - (void)setDefaultOptions:(RNNNavigationOptions *)defaultOptions {
  33. _defaultOptions = defaultOptions;
  34. }
  35. @end