react-native-navigation的迁移库

RNNTabBarController.m 3.4KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102
  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. [self.presenter applyOptionsOnInit:self.options];
  29. return self;
  30. }
  31. - (void)willMoveToParentViewController:(UIViewController *)parent {
  32. if (parent) {
  33. [_presenter applyOptionsOnWillMoveToParentViewController:self.resolveOptions];
  34. }
  35. }
  36. - (void)onChildWillAppear {
  37. [_presenter applyOptions:self.resolveOptions];
  38. [((UIViewController<RNNParentProtocol> *)self.parentViewController) onChildWillAppear];
  39. }
  40. - (RNNNavigationOptions *)resolveOptions {
  41. return [(RNNNavigationOptions *)[self.getCurrentChild.resolveOptions.copy mergeOptions:self.options] withDefault:self.defaultOptions];
  42. }
  43. - (void)mergeOptions:(RNNNavigationOptions *)options {
  44. [_presenter mergeOptions:options currentOptions:self.options defaultOptions:self.defaultOptions];
  45. [((UIViewController<RNNLayoutProtocol> *)self.parentViewController) mergeOptions:options];
  46. }
  47. - (void)overrideOptions:(RNNNavigationOptions *)options {
  48. [self.options overrideOptions:options];
  49. }
  50. - (UIInterfaceOrientationMask)supportedInterfaceOrientations {
  51. return self.selectedViewController.supportedInterfaceOrientations;
  52. }
  53. - (void)setSelectedIndexByComponentID:(NSString *)componentID {
  54. for (id child in self.childViewControllers) {
  55. UIViewController<RNNLayoutProtocol>* vc = child;
  56. if ([vc conformsToProtocol:@protocol(RNNLayoutProtocol)] && [vc.layoutInfo.componentId isEqualToString:componentID]) {
  57. [self setSelectedIndex:[self.childViewControllers indexOfObject:child]];
  58. }
  59. }
  60. }
  61. - (void)setSelectedIndex:(NSUInteger)selectedIndex {
  62. _currentTabIndex = selectedIndex;
  63. [super setSelectedIndex:selectedIndex];
  64. }
  65. - (UIViewController *)getCurrentChild {
  66. return self.selectedViewController;
  67. }
  68. - (UIViewController<RNNLeafProtocol> *)getCurrentLeaf {
  69. return [[self getCurrentChild] getCurrentLeaf];
  70. }
  71. - (UIStatusBarStyle)preferredStatusBarStyle {
  72. return ((UIViewController<RNNParentProtocol>*)self.selectedViewController).preferredStatusBarStyle;
  73. }
  74. #pragma mark UITabBarControllerDelegate
  75. - (void)tabBarController:(UITabBarController *)tabBarController didSelectViewController:(UIViewController *)viewController {
  76. [_eventEmitter sendBottomTabSelected:@(tabBarController.selectedIndex) unselected:@(_currentTabIndex)];
  77. _currentTabIndex = tabBarController.selectedIndex;
  78. }
  79. @end