react-native-navigation的迁移库

RNNTabBarController.m 1.6KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  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. - (UIInterfaceOrientationMask)supportedInterfaceOrientations {
  14. return self.selectedViewController.supportedInterfaceOrientations;
  15. }
  16. - (void)setSelectedIndexByComponentID:(NSString *)componentID {
  17. for (id child in self.childViewControllers) {
  18. RNNRootViewController* vc = child;
  19. if ([vc.componentId isEqualToString:componentID]) {
  20. [self setSelectedIndex:[self.childViewControllers indexOfObject:child]];
  21. }
  22. }
  23. }
  24. - (void)setSelectedIndex:(NSUInteger)selectedIndex {
  25. _currentTabIndex = selectedIndex;
  26. [super setSelectedIndex:selectedIndex];
  27. }
  28. - (void)mergeOptions:(RNNOptions *)options {
  29. [self.getLeafViewController mergeOptions:options];
  30. }
  31. - (UIViewController *)getLeafViewController {
  32. return ((UIViewController<RNNRootViewProtocol>*)self.selectedViewController).getLeafViewController;
  33. }
  34. - (UIStatusBarStyle)preferredStatusBarStyle {
  35. return ((UIViewController<RNNRootViewProtocol>*)self.selectedViewController).preferredStatusBarStyle;
  36. }
  37. #pragma mark UITabBarControllerDelegate
  38. - (void)tabBarController:(UITabBarController *)tabBarController didSelectViewController:(UIViewController *)viewController {
  39. [_eventEmitter sendBottomTabSelected:@(tabBarController.selectedIndex) unselected:@(_currentTabIndex)];
  40. _currentTabIndex = tabBarController.selectedIndex;
  41. }
  42. @end