react-native-navigation的迁移库

RNNTabBarController.m 1.5KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. #import "RNNTabBarController.h"
  2. @implementation RNNTabBarController {
  3. NSUInteger _currentTabIndex;
  4. }
  5. - (void)setViewControllers:(NSArray<__kindof UIViewController *> *)viewControllers {
  6. [super setViewControllers:viewControllers];
  7. [self.presenter applyOptionsOnSetViewControllers:self.resolveOptions];
  8. }
  9. - (id<UITabBarControllerDelegate>)delegate {
  10. return self;
  11. }
  12. - (UIViewController *)getCurrentChild {
  13. return self.selectedViewController;
  14. }
  15. - (UIInterfaceOrientationMask)supportedInterfaceOrientations {
  16. return self.selectedViewController.supportedInterfaceOrientations;
  17. }
  18. - (void)setSelectedIndexByComponentID:(NSString *)componentID {
  19. for (id child in self.childViewControllers) {
  20. UIViewController<RNNLayoutProtocol>* vc = child;
  21. if ([vc conformsToProtocol:@protocol(RNNLayoutProtocol)] && [vc.layoutInfo.componentId isEqualToString:componentID]) {
  22. [self setSelectedIndex:[self.childViewControllers indexOfObject:child]];
  23. }
  24. }
  25. }
  26. - (void)setSelectedIndex:(NSUInteger)selectedIndex {
  27. _currentTabIndex = selectedIndex;
  28. [super setSelectedIndex:selectedIndex];
  29. }
  30. - (UIStatusBarStyle)preferredStatusBarStyle {
  31. return self.selectedViewController.preferredStatusBarStyle;
  32. }
  33. #pragma mark UITabBarControllerDelegate
  34. - (void)tabBarController:(UITabBarController *)tabBarController didSelectViewController:(UIViewController *)viewController {
  35. [self.eventEmitter sendBottomTabSelected:@(tabBarController.selectedIndex) unselected:@(_currentTabIndex)];
  36. _currentTabIndex = tabBarController.selectedIndex;
  37. }
  38. @end