react-native-navigation的迁移库

RNNTabBarController.m 3.0KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  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. - (UITabBarItem *)tabBarItem {
  44. return super.tabBarItem ? super.tabBarItem : self.viewControllers.lastObject.tabBarItem;
  45. }
  46. - (UIInterfaceOrientationMask)supportedInterfaceOrientations {
  47. return self.selectedViewController.supportedInterfaceOrientations;
  48. }
  49. - (void)setSelectedIndexByComponentID:(NSString *)componentID {
  50. for (id child in self.childViewControllers) {
  51. UIViewController<RNNLayoutProtocol>* vc = child;
  52. if ([vc conformsToProtocol:@protocol(RNNLayoutProtocol)] && [vc.layoutInfo.componentId isEqualToString:componentID]) {
  53. [self setSelectedIndex:[self.childViewControllers indexOfObject:child]];
  54. }
  55. }
  56. }
  57. - (void)setSelectedIndex:(NSUInteger)selectedIndex {
  58. _currentTabIndex = selectedIndex;
  59. [super setSelectedIndex:selectedIndex];
  60. }
  61. - (UIViewController *)getCurrentChild {
  62. return ((UIViewController<RNNParentProtocol>*)self.selectedViewController).getCurrentChild;
  63. }
  64. - (UIStatusBarStyle)preferredStatusBarStyle {
  65. return ((UIViewController<RNNParentProtocol>*)self.selectedViewController).preferredStatusBarStyle;
  66. }
  67. #pragma mark UITabBarControllerDelegate
  68. - (void)tabBarController:(UITabBarController *)tabBarController didSelectViewController:(UIViewController *)viewController {
  69. [_eventEmitter sendBottomTabSelected:@(tabBarController.selectedIndex) unselected:@(_currentTabIndex)];
  70. _currentTabIndex = tabBarController.selectedIndex;
  71. }
  72. @end