react-native-navigation的迁移库

RNNTabBarController.m 1.9KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. #import "RNNTabBarController.h"
  2. #define kTabBarHiddenDuration 0.3
  3. @implementation RNNTabBarController {
  4. NSUInteger _currentTabIndex;
  5. RNNEventEmitter *_eventEmitter;
  6. }
  7. - (instancetype)initWithEventEmitter:(id)eventEmitter {
  8. self = [super init];
  9. _eventEmitter = eventEmitter;
  10. self.delegate = self;
  11. return self;
  12. }
  13. - (void)performOnChildLoad:(RNNNavigationOptions *)childOptions {
  14. [_presenter presentWithChildOptions:childOptions on:self];
  15. if ([self.parentViewController respondsToSelector:@selector(performOnChildLoad:)]) {
  16. [self.parentViewController performSelector:@selector(performOnChildLoad:) withObject:childOptions];
  17. }
  18. }
  19. - (UIInterfaceOrientationMask)supportedInterfaceOrientations {
  20. return self.selectedViewController.supportedInterfaceOrientations;
  21. }
  22. - (void)setSelectedIndexByComponentID:(NSString *)componentID {
  23. for (id child in self.childViewControllers) {
  24. UIViewController<RNNParentProtocol>* vc = child;
  25. if ([vc.layoutInfo.componentId isEqualToString:componentID]) {
  26. [self setSelectedIndex:[self.childViewControllers indexOfObject:child]];
  27. }
  28. }
  29. }
  30. - (void)setSelectedIndex:(NSUInteger)selectedIndex {
  31. _currentTabIndex = selectedIndex;
  32. [super setSelectedIndex:selectedIndex];
  33. }
  34. - (UIViewController *)getLeafViewController {
  35. return ((UIViewController<RNNParentProtocol>*)self.selectedViewController).getLeafViewController;
  36. }
  37. - (UIStatusBarStyle)preferredStatusBarStyle {
  38. return ((UIViewController<RNNParentProtocol>*)self.selectedViewController).preferredStatusBarStyle;
  39. }
  40. - (void)setViewControllers:(NSArray<__kindof UIViewController *> *)viewControllers {
  41. [super setViewControllers:viewControllers];
  42. }
  43. #pragma mark UITabBarControllerDelegate
  44. - (void)tabBarController:(UITabBarController *)tabBarController didSelectViewController:(UIViewController *)viewController {
  45. [_eventEmitter sendBottomTabSelected:@(tabBarController.selectedIndex) unselected:@(_currentTabIndex)];
  46. _currentTabIndex = tabBarController.selectedIndex;
  47. }
  48. @end