react-native-navigation的迁移库

RNNTabBarController.m 1.5KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  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. UIViewController<RNNRootViewProtocol>* vc = child;
  19. if ([vc.layoutInfo.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. - (UIViewController *)getLeafViewController {
  29. return ((UIViewController<RNNRootViewProtocol>*)self.selectedViewController).getLeafViewController;
  30. }
  31. - (UIStatusBarStyle)preferredStatusBarStyle {
  32. return ((UIViewController<RNNRootViewProtocol>*)self.selectedViewController).preferredStatusBarStyle;
  33. }
  34. #pragma mark UITabBarControllerDelegate
  35. - (void)tabBarController:(UITabBarController *)tabBarController didSelectViewController:(UIViewController *)viewController {
  36. [_eventEmitter sendBottomTabSelected:@(tabBarController.selectedIndex) unselected:@(_currentTabIndex)];
  37. _currentTabIndex = tabBarController.selectedIndex;
  38. }
  39. @end