react-native-navigation的迁移库

RNNTabBarController.m 2.9KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  1. #import "RNNTabBarController.h"
  2. @implementation RNNTabBarController {
  3. NSUInteger _currentTabIndex;
  4. }
  5. - (instancetype)initWithLayoutInfo:(RNNLayoutInfo *)layoutInfo
  6. childViewControllers:(NSArray *)childViewControllers
  7. options:(RNNNavigationOptions *)options
  8. presenter:(RNNTabBarPresenter *)presenter
  9. eventEmitter:(RNNEventEmitter *)eventEmitter {
  10. self = [self initWithLayoutInfo:layoutInfo childViewControllers:childViewControllers options:options presenter:presenter];
  11. _eventEmitter = eventEmitter;
  12. return self;
  13. }
  14. - (instancetype)initWithLayoutInfo:(RNNLayoutInfo *)layoutInfo
  15. childViewControllers:(NSArray *)childViewControllers
  16. options:(RNNNavigationOptions *)options
  17. presenter:(RNNTabBarPresenter *)presenter {
  18. self = [super init];
  19. self.delegate = self;
  20. self.options = options;
  21. self.layoutInfo = layoutInfo;
  22. self.presenter = presenter;
  23. [self.presenter bindViewController:self];
  24. [self setViewControllers:childViewControllers];
  25. return self;
  26. }
  27. - (void)willMoveToParentViewController:(UIViewController *)parent {
  28. if (parent) {
  29. [_presenter applyOptionsOnWillMoveToParentViewController:self.options];
  30. }
  31. }
  32. - (void)onChildWillAppear {
  33. [_presenter applyOptions:self.resolveOptions];
  34. [((UIViewController<RNNParentProtocol> *)self.parentViewController) onChildWillAppear];
  35. }
  36. - (RNNNavigationOptions *)resolveOptions {
  37. return (RNNNavigationOptions *)[self.getCurrentChild.resolveOptions.copy mergeOptions:self.options];
  38. }
  39. - (void)mergeOptions:(RNNNavigationOptions *)options {
  40. [_presenter mergeOptions:options resolvedOptions:self.resolveOptions];
  41. [((UIViewController<RNNLayoutProtocol> *)self.parentViewController) mergeOptions:options];
  42. }
  43. - (UIInterfaceOrientationMask)supportedInterfaceOrientations {
  44. return self.selectedViewController.supportedInterfaceOrientations;
  45. }
  46. - (void)setSelectedIndexByComponentID:(NSString *)componentID {
  47. for (id child in self.childViewControllers) {
  48. UIViewController<RNNLayoutProtocol>* vc = child;
  49. if ([vc conformsToProtocol:@protocol(RNNLayoutProtocol)] && [vc.layoutInfo.componentId isEqualToString:componentID]) {
  50. [self setSelectedIndex:[self.childViewControllers indexOfObject:child]];
  51. }
  52. }
  53. }
  54. - (void)setSelectedIndex:(NSUInteger)selectedIndex {
  55. _currentTabIndex = selectedIndex;
  56. [super setSelectedIndex:selectedIndex];
  57. }
  58. - (UIViewController *)getCurrentChild {
  59. return ((UIViewController<RNNParentProtocol>*)self.selectedViewController).getCurrentChild;
  60. }
  61. - (UIStatusBarStyle)preferredStatusBarStyle {
  62. return ((UIViewController<RNNParentProtocol>*)self.selectedViewController).preferredStatusBarStyle;
  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