react-native-navigation的迁移库

BottomTabPresenter.m 3.0KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  1. #import "BottomTabPresenter.h"
  2. #import "RNNTabBarItemCreator.h"
  3. #import "UIViewController+RNNOptions.h"
  4. #import "RNNDotIndicatorPresenter.h"
  5. #import "UIViewController+LayoutProtocol.h"
  6. @interface BottomTabPresenter ()
  7. @property(nonatomic, strong) RNNDotIndicatorPresenter* dotIndicatorPresenter;
  8. @end
  9. @implementation BottomTabPresenter
  10. - (instancetype)initWithDefaultOptions:(RNNNavigationOptions *)defaultOptions {
  11. self = [super init];
  12. self.defaultOptions = defaultOptions;
  13. self.dotIndicatorPresenter = [[RNNDotIndicatorPresenter alloc] initWithDefaultOptions:defaultOptions];
  14. return self;
  15. }
  16. - (void)applyOptions:(RNNNavigationOptions *)options {
  17. RNNNavigationOptions * withDefault = [options withDefault:self.defaultOptions];
  18. if (withDefault.bottomTab.badge.hasValue && [self.boundViewController.parentViewController isKindOfClass:[UITabBarController class]]) {
  19. [self.boundViewController setTabBarItemBadge:withDefault.bottomTab.badge.get];
  20. }
  21. if (withDefault.bottomTab.badgeColor.hasValue && [self.boundViewController.parentViewController isKindOfClass:[UITabBarController class]]) {
  22. [self.boundViewController setTabBarItemBadgeColor:withDefault.bottomTab.badgeColor.get];
  23. }
  24. }
  25. - (void)applyOptionsOnWillMoveToParentViewController:(RNNNavigationOptions *)options {
  26. RNNNavigationOptions * withDefault = [options withDefault:self.defaultOptions];
  27. if (withDefault.bottomTab.hasValue) {
  28. [self updateTabBarItem:self.boundViewController.tabBarItem bottomTabOptions:withDefault.bottomTab];
  29. }
  30. }
  31. - (void)mergeOptions:(RNNNavigationOptions *)options resolvedOptions:(RNNNavigationOptions *)resolvedOptions {
  32. RNNNavigationOptions* withDefault = (RNNNavigationOptions *) [[resolvedOptions withDefault:self.defaultOptions] overrideOptions:options];
  33. if (options.bottomTab.badge.hasValue) {
  34. [self.boundViewController setTabBarItemBadge:options.bottomTab.badge.get];
  35. }
  36. if (options.bottomTab.badgeColor.hasValue && [self.boundViewController.parentViewController isKindOfClass:[UITabBarController class]]) {
  37. [self.boundViewController setTabBarItemBadgeColor:options.bottomTab.badgeColor.get];
  38. }
  39. if ([options.bottomTab.dotIndicator hasValue] && [self.boundViewController.parentViewController isKindOfClass:[UITabBarController class]]) {
  40. [[self dotIndicatorPresenter] apply:self.boundViewController:options.bottomTab.dotIndicator];
  41. }
  42. if (options.bottomTab.hasValue) {
  43. [self updateTabBarItem:self.boundViewController.tabBarItem bottomTabOptions:withDefault.bottomTab];
  44. }
  45. }
  46. - (void)updateTabBarItem:(UITabBarItem *)tabItem bottomTabOptions:(RNNBottomTabOptions *)bottomTabOptions {
  47. self.boundViewController.tabBarItem = [RNNTabBarItemCreator updateTabBarItem:self.boundViewController.tabBarItem bottomTabOptions:bottomTabOptions];
  48. }
  49. - (void)applyDotIndicator:(UIViewController *)child {
  50. [_dotIndicatorPresenter apply:child:[child resolveOptions].bottomTab.dotIndicator];
  51. }
  52. @end