react-native-navigation的迁移库

RNNTabBarController.m 3.3KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101
  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. defaultOptions:(RNNNavigationOptions *)defaultOptions
  9. presenter:(RNNTabBarPresenter *)presenter
  10. eventEmitter:(RNNEventEmitter *)eventEmitter {
  11. self = [self initWithLayoutInfo:layoutInfo childViewControllers:childViewControllers options:options defaultOptions:defaultOptions presenter:presenter];
  12. _eventEmitter = eventEmitter;
  13. return self;
  14. }
  15. - (instancetype)initWithLayoutInfo:(RNNLayoutInfo *)layoutInfo
  16. childViewControllers:(NSArray *)childViewControllers
  17. options:(RNNNavigationOptions *)options
  18. defaultOptions:(RNNNavigationOptions *)defaultOptions
  19. presenter:(RNNTabBarPresenter *)presenter {
  20. self = [super init];
  21. self.delegate = self;
  22. self.options = options;
  23. self.defaultOptions = defaultOptions;
  24. self.layoutInfo = layoutInfo;
  25. self.presenter = presenter;
  26. [self.presenter bindViewController:self];
  27. [self setViewControllers:childViewControllers];
  28. return self;
  29. }
  30. - (void)willMoveToParentViewController:(UIViewController *)parent {
  31. if (parent) {
  32. [_presenter applyOptionsOnWillMoveToParentViewController:self.resolveOptions];
  33. }
  34. }
  35. - (void)onChildWillAppear {
  36. [_presenter applyOptions:self.resolveOptions];
  37. [((UIViewController<RNNParentProtocol> *)self.parentViewController) onChildWillAppear];
  38. }
  39. - (RNNNavigationOptions *)resolveOptions {
  40. return [(RNNNavigationOptions *)[self.getCurrentChild.resolveOptions.copy mergeOptions:self.options] withDefault:self.defaultOptions];
  41. }
  42. - (void)mergeOptions:(RNNNavigationOptions *)options {
  43. [_presenter mergeOptions:options currentOptions:self.options defaultOptions:self.defaultOptions];
  44. [((UIViewController<RNNLayoutProtocol> *)self.parentViewController) mergeOptions:options];
  45. }
  46. - (void)overrideOptions:(RNNNavigationOptions *)options {
  47. [self.options overrideOptions:options];
  48. }
  49. - (UIInterfaceOrientationMask)supportedInterfaceOrientations {
  50. return self.selectedViewController.supportedInterfaceOrientations;
  51. }
  52. - (void)setSelectedIndexByComponentID:(NSString *)componentID {
  53. for (id child in self.childViewControllers) {
  54. UIViewController<RNNLayoutProtocol>* vc = child;
  55. if ([vc conformsToProtocol:@protocol(RNNLayoutProtocol)] && [vc.layoutInfo.componentId isEqualToString:componentID]) {
  56. [self setSelectedIndex:[self.childViewControllers indexOfObject:child]];
  57. }
  58. }
  59. }
  60. - (void)setSelectedIndex:(NSUInteger)selectedIndex {
  61. _currentTabIndex = selectedIndex;
  62. [super setSelectedIndex:selectedIndex];
  63. }
  64. - (UIViewController *)getCurrentChild {
  65. return self.selectedViewController;
  66. }
  67. - (UIViewController<RNNLeafProtocol> *)getCurrentLeaf {
  68. return [[self getCurrentChild] getCurrentLeaf];
  69. }
  70. - (UIStatusBarStyle)preferredStatusBarStyle {
  71. return ((UIViewController<RNNParentProtocol>*)self.selectedViewController).preferredStatusBarStyle;
  72. }
  73. #pragma mark UITabBarControllerDelegate
  74. - (void)tabBarController:(UITabBarController *)tabBarController didSelectViewController:(UIViewController *)viewController {
  75. [_eventEmitter sendBottomTabSelected:@(tabBarController.selectedIndex) unselected:@(_currentTabIndex)];
  76. _currentTabIndex = tabBarController.selectedIndex;
  77. }
  78. @end