react-native-navigation的迁移库

RNNTabBarController.m 3.3KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113
  1. #import "RNNTabBarController.h"
  2. #define kTabBarHiddenDuration 0.3
  3. @implementation RNNTabBarController {
  4. NSUInteger _currentTabIndex;
  5. RNNEventEmitter *_eventEmitter;
  6. }
  7. - (instancetype)initWithLayoutInfo:(RNNLayoutInfo *)layoutInfo
  8. childViewControllers:(NSArray *)childViewControllers
  9. options:(RNNNavigationOptions *)options
  10. presenter:(RNNBasePresenter *)presenter
  11. eventEmitter:(RNNEventEmitter *)eventEmitter {
  12. self = [self initWithLayoutInfo:layoutInfo childViewControllers:childViewControllers options:options presenter:presenter];
  13. _eventEmitter = eventEmitter;
  14. return self;
  15. }
  16. - (instancetype)initWithLayoutInfo:(RNNLayoutInfo *)layoutInfo
  17. childViewControllers:(NSArray *)childViewControllers
  18. options:(RNNNavigationOptions *)options
  19. presenter:(RNNViewControllerPresenter *)presenter {
  20. self = [super init];
  21. self.delegate = self;
  22. self.options = options;
  23. self.layoutInfo = layoutInfo;
  24. self.presenter = presenter;
  25. [self.presenter bindViewController:self];
  26. [self setViewControllers:childViewControllers];
  27. return self;
  28. }
  29. - (instancetype)initWithEventEmitter:(id)eventEmitter {
  30. self = [super init];
  31. _eventEmitter = eventEmitter;
  32. self.delegate = self;
  33. return self;
  34. }
  35. - (void)willMoveToParentViewController:(UIViewController *)parent {
  36. if (parent) {
  37. [_presenter applyOptionsOnWillMoveToParentViewController:self.options];
  38. }
  39. }
  40. - (void)onChildWillAppear {
  41. [_presenter applyOptions:self.resolveOptions];
  42. [((UIViewController<RNNParentProtocol> *)self.parentViewController) onChildWillAppear];
  43. }
  44. - (RNNNavigationOptions *)resolveOptions {
  45. return (RNNNavigationOptions *)[self.getCurrentChild.resolveOptions.copy mergeOptions:self.options];
  46. }
  47. - (void)mergeOptions:(RNNNavigationOptions *)options {
  48. [_presenter mergeOptions:options];
  49. [((UIViewController<RNNLayoutProtocol> *)self.parentViewController) mergeOptions:options];
  50. }
  51. - (void)viewWillAppear:(BOOL)animated {
  52. [super viewWillAppear:animated];
  53. [_presenter applyOptions:self.options];
  54. }
  55. - (UITabBarItem *)tabBarItem {
  56. return super.tabBarItem ? super.tabBarItem : self.viewControllers.lastObject.tabBarItem;
  57. }
  58. - (UIInterfaceOrientationMask)supportedInterfaceOrientations {
  59. return self.selectedViewController.supportedInterfaceOrientations;
  60. }
  61. - (void)setSelectedIndexByComponentID:(NSString *)componentID {
  62. for (id child in self.childViewControllers) {
  63. UIViewController<RNNParentProtocol>* vc = child;
  64. if ([vc.layoutInfo.componentId isEqualToString:componentID]) {
  65. [self setSelectedIndex:[self.childViewControllers indexOfObject:child]];
  66. }
  67. }
  68. }
  69. - (void)setSelectedIndex:(NSUInteger)selectedIndex {
  70. _currentTabIndex = selectedIndex;
  71. [super setSelectedIndex:selectedIndex];
  72. }
  73. - (UIViewController *)getCurrentChild {
  74. return ((UIViewController<RNNParentProtocol>*)self.selectedViewController).getCurrentChild;
  75. }
  76. - (UIStatusBarStyle)preferredStatusBarStyle {
  77. return ((UIViewController<RNNParentProtocol>*)self.selectedViewController).preferredStatusBarStyle;
  78. }
  79. #pragma mark UITabBarControllerDelegate
  80. - (void)tabBarController:(UITabBarController *)tabBarController didSelectViewController:(UIViewController *)viewController {
  81. [_eventEmitter sendBottomTabSelected:@(tabBarController.selectedIndex) unselected:@(_currentTabIndex)];
  82. _currentTabIndex = tabBarController.selectedIndex;
  83. }
  84. @end