react-native-navigation的迁移库

RNNTabBarController.m 3.3KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112
  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.options = options;
  22. self.layoutInfo = layoutInfo;
  23. self.presenter = presenter;
  24. [self.presenter bindViewController:self];
  25. [self setViewControllers:childViewControllers];
  26. return self;
  27. }
  28. - (instancetype)initWithEventEmitter:(id)eventEmitter {
  29. self = [super init];
  30. _eventEmitter = eventEmitter;
  31. self.delegate = self;
  32. return self;
  33. }
  34. - (void)willMoveToParentViewController:(UIViewController *)parent {
  35. if (parent) {
  36. [_presenter applyOptionsOnWillMoveToParentViewController:self.options];
  37. }
  38. }
  39. - (void)onChildWillAppear {
  40. [_presenter applyOptions:self.resolveOptions];
  41. [((UIViewController<RNNParentProtocol> *)self.parentViewController) onChildWillAppear];
  42. }
  43. - (RNNNavigationOptions *)resolveOptions {
  44. return (RNNNavigationOptions *)[self.getCurrentChild.resolveOptions.copy mergeOptions:self.options];
  45. }
  46. - (void)mergeOptions:(RNNNavigationOptions *)options {
  47. [_presenter mergeOptions:options];
  48. [((UIViewController<RNNLayoutProtocol> *)self.parentViewController) mergeOptions:options];
  49. }
  50. - (void)viewWillAppear:(BOOL)animated {
  51. [super viewWillAppear:animated];
  52. [_presenter applyOptions:self.options];
  53. }
  54. - (UITabBarItem *)tabBarItem {
  55. return super.tabBarItem ? super.tabBarItem : self.viewControllers.lastObject.tabBarItem;
  56. }
  57. - (UIInterfaceOrientationMask)supportedInterfaceOrientations {
  58. return self.selectedViewController.supportedInterfaceOrientations;
  59. }
  60. - (void)setSelectedIndexByComponentID:(NSString *)componentID {
  61. for (id child in self.childViewControllers) {
  62. UIViewController<RNNParentProtocol>* vc = child;
  63. if ([vc.layoutInfo.componentId isEqualToString:componentID]) {
  64. [self setSelectedIndex:[self.childViewControllers indexOfObject:child]];
  65. }
  66. }
  67. }
  68. - (void)setSelectedIndex:(NSUInteger)selectedIndex {
  69. _currentTabIndex = selectedIndex;
  70. [super setSelectedIndex:selectedIndex];
  71. }
  72. - (UIViewController *)getCurrentChild {
  73. return ((UIViewController<RNNParentProtocol>*)self.selectedViewController).getCurrentChild;
  74. }
  75. - (UIStatusBarStyle)preferredStatusBarStyle {
  76. return ((UIViewController<RNNParentProtocol>*)self.selectedViewController).preferredStatusBarStyle;
  77. }
  78. #pragma mark UITabBarControllerDelegate
  79. - (void)tabBarController:(UITabBarController *)tabBarController didSelectViewController:(UIViewController *)viewController {
  80. [_eventEmitter sendBottomTabSelected:@(tabBarController.selectedIndex) unselected:@(_currentTabIndex)];
  81. _currentTabIndex = tabBarController.selectedIndex;
  82. }
  83. @end