react-native-navigation的迁移库

RNNTabBarController.m 3.2KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  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 ((UIViewController<RNNParentProtocol>*)self.selectedViewController).getCurrentChild;
  66. }
  67. - (UIStatusBarStyle)preferredStatusBarStyle {
  68. return ((UIViewController<RNNParentProtocol>*)self.selectedViewController).preferredStatusBarStyle;
  69. }
  70. #pragma mark UITabBarControllerDelegate
  71. - (void)tabBarController:(UITabBarController *)tabBarController didSelectViewController:(UIViewController *)viewController {
  72. [_eventEmitter sendBottomTabSelected:@(tabBarController.selectedIndex) unselected:@(_currentTabIndex)];
  73. _currentTabIndex = tabBarController.selectedIndex;
  74. }
  75. @end