react-native-navigation的迁移库

RNNTabBarController.m 2.9KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  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. optionsResolver:(RNNParentOptionsResolver *)optionsResolver
  11. presenter:(RNNBasePresenter *)presenter
  12. eventEmitter:(RNNEventEmitter *)eventEmitter {
  13. self = [self initWithLayoutInfo:layoutInfo childViewControllers:childViewControllers options:options optionsResolver:optionsResolver presenter:presenter];
  14. _eventEmitter = eventEmitter;
  15. return self;
  16. }
  17. - (instancetype)initWithLayoutInfo:(RNNLayoutInfo *)layoutInfo
  18. childViewControllers:(NSArray *)childViewControllers
  19. options:(RNNNavigationOptions *)options
  20. optionsResolver:(RNNParentOptionsResolver *)optionsResolver
  21. presenter:(RNNBasePresenter *)presenter {
  22. self = [super init];
  23. self.presenter = presenter;
  24. self.options = options;
  25. self.layoutInfo = layoutInfo;
  26. self.optionsResolver = optionsResolver;
  27. [self setViewControllers:childViewControllers];
  28. return self;
  29. }
  30. - (instancetype)initWithEventEmitter:(id)eventEmitter {
  31. self = [super init];
  32. _eventEmitter = eventEmitter;
  33. self.delegate = self;
  34. return self;
  35. }
  36. - (UIInterfaceOrientationMask)supportedInterfaceOrientations {
  37. return self.selectedViewController.supportedInterfaceOrientations;
  38. }
  39. - (void)setSelectedIndexByComponentID:(NSString *)componentID {
  40. for (id child in self.childViewControllers) {
  41. UIViewController<RNNParentProtocol>* vc = child;
  42. if ([vc.layoutInfo.componentId isEqualToString:componentID]) {
  43. [self setSelectedIndex:[self.childViewControllers indexOfObject:child]];
  44. }
  45. }
  46. }
  47. - (void)setSelectedIndex:(NSUInteger)selectedIndex {
  48. _currentTabIndex = selectedIndex;
  49. [super setSelectedIndex:selectedIndex];
  50. }
  51. - (UIViewController *)getLeafViewController {
  52. return ((UIViewController<RNNParentProtocol>*)self.selectedViewController).getLeafViewController;
  53. }
  54. - (UIStatusBarStyle)preferredStatusBarStyle {
  55. return ((UIViewController<RNNParentProtocol>*)self.selectedViewController).preferredStatusBarStyle;
  56. }
  57. - (void)willMoveToParentViewController:(UIViewController *)parent {
  58. [_optionsResolver resolve:self with:self.viewControllers];
  59. [_presenter present:self.options onViewControllerDidLoad:self];
  60. }
  61. - (void)mergeOptions:(RNNNavigationOptions *)options {
  62. [self.options mergeOptions:options overrideOptions:YES];
  63. [self.presenter present:self.options onViewControllerWillAppear:self];
  64. }
  65. #pragma mark UITabBarControllerDelegate
  66. - (void)tabBarController:(UITabBarController *)tabBarController didSelectViewController:(UIViewController *)viewController {
  67. [_eventEmitter sendBottomTabSelected:@(tabBarController.selectedIndex) unselected:@(_currentTabIndex)];
  68. _currentTabIndex = tabBarController.selectedIndex;
  69. }
  70. @end