react-native-navigation的迁移库

RNNBottomTabsController.m 2.3KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  1. #import "RNNBottomTabsController.h"
  2. #import "UITabBarController+RNNUtils.h"
  3. @implementation RNNBottomTabsController {
  4. NSUInteger _currentTabIndex;
  5. BottomTabsBaseAttacher* _bottomTabsAttacher;
  6. }
  7. - (instancetype)initWithLayoutInfo:(RNNLayoutInfo *)layoutInfo
  8. creator:(id<RNNComponentViewCreator>)creator
  9. options:(RNNNavigationOptions *)options
  10. defaultOptions:(RNNNavigationOptions *)defaultOptions
  11. presenter:(RNNBasePresenter *)presenter
  12. eventEmitter:(RNNEventEmitter *)eventEmitter
  13. childViewControllers:(NSArray *)childViewControllers
  14. bottomTabsAttacher:(BottomTabsBaseAttacher *)bottomTabsAttacher {
  15. self = [super initWithLayoutInfo:layoutInfo creator:creator options:options defaultOptions:defaultOptions presenter:presenter eventEmitter:eventEmitter childViewControllers:childViewControllers];
  16. _bottomTabsAttacher = bottomTabsAttacher;
  17. return self;
  18. }
  19. - (id<UITabBarControllerDelegate>)delegate {
  20. return self;
  21. }
  22. - (void)render {
  23. [_bottomTabsAttacher attach:self];
  24. }
  25. - (void)viewDidLayoutSubviews {
  26. [self.presenter viewDidLayoutSubviews];
  27. }
  28. - (UIViewController *)getCurrentChild {
  29. return self.selectedViewController;
  30. }
  31. - (CGFloat)getBottomTabsHeight {
  32. return self.tabBar.frame.size.height;
  33. }
  34. - (void)setSelectedIndexByComponentID:(NSString *)componentID {
  35. for (id child in self.childViewControllers) {
  36. UIViewController<RNNLayoutProtocol>* vc = child;
  37. if ([vc conformsToProtocol:@protocol(RNNLayoutProtocol)] && [vc.layoutInfo.componentId isEqualToString:componentID]) {
  38. [self setSelectedIndex:[self.childViewControllers indexOfObject:child]];
  39. }
  40. }
  41. }
  42. - (void)setSelectedIndex:(NSUInteger)selectedIndex {
  43. _currentTabIndex = selectedIndex;
  44. [super setSelectedIndex:selectedIndex];
  45. }
  46. - (UIStatusBarStyle)preferredStatusBarStyle {
  47. return [[self presenter] getStatusBarStyle:self.resolveOptions];
  48. }
  49. #pragma mark UITabBarControllerDelegate
  50. - (void)tabBarController:(UITabBarController *)tabBarController didSelectViewController:(UIViewController *)viewController {
  51. [self.eventEmitter sendBottomTabSelected:@(tabBarController.selectedIndex) unselected:@(_currentTabIndex)];
  52. _currentTabIndex = tabBarController.selectedIndex;
  53. }
  54. @end