react-native-navigation的迁移库

RNNBottomTabsController.m 1.5KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. #import "RNNBottomTabsController.h"
  2. @implementation RNNBottomTabsController {
  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. - (void)setSelectedIndexByComponentID:(NSString *)componentID {
  22. for (id child in self.childViewControllers) {
  23. UIViewController<RNNLayoutProtocol>* vc = child;
  24. if ([vc conformsToProtocol:@protocol(RNNLayoutProtocol)] && [vc.layoutInfo.componentId isEqualToString:componentID]) {
  25. [self setSelectedIndex:[self.childViewControllers indexOfObject:child]];
  26. }
  27. }
  28. }
  29. - (void)setSelectedIndex:(NSUInteger)selectedIndex {
  30. _currentTabIndex = selectedIndex;
  31. [super setSelectedIndex:selectedIndex];
  32. }
  33. - (UIStatusBarStyle)preferredStatusBarStyle {
  34. return [[self presenter] getStatusBarStyle:self.resolveOptions];
  35. }
  36. #pragma mark UITabBarControllerDelegate
  37. - (void)tabBarController:(UITabBarController *)tabBarController didSelectViewController:(UIViewController *)viewController {
  38. [self.eventEmitter sendBottomTabSelected:@(tabBarController.selectedIndex) unselected:@(_currentTabIndex)];
  39. _currentTabIndex = tabBarController.selectedIndex;
  40. }
  41. @end