react-native-navigation的迁移库

RNNTabBarController.m 2.8KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  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.presenter present:options onViewControllerWillAppear:self];
  63. }
  64. #pragma mark UITabBarControllerDelegate
  65. - (void)tabBarController:(UITabBarController *)tabBarController didSelectViewController:(UIViewController *)viewController {
  66. [_eventEmitter sendBottomTabSelected:@(tabBarController.selectedIndex) unselected:@(_currentTabIndex)];
  67. _currentTabIndex = tabBarController.selectedIndex;
  68. }
  69. @end