react-native-navigation的迁移库

RNNTabBarController.m 1.6KB

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