react-native-navigation的迁移库

RNNTabBarController.m 2.4KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  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. - (void)performOnChildLoad:(RNNNavigationOptions *)childOptions {
  14. RNNNavigationOptions* combinedOptions = [_presenter presentWithChildOptions:childOptions on:self];
  15. if ([self.parentViewController respondsToSelector:@selector(performOnChildLoad:)]) {
  16. [self.parentViewController performSelector:@selector(performOnChildLoad:) withObject:combinedOptions];
  17. }
  18. }
  19. - (void)performOnChildWillAppear:(RNNNavigationOptions *)childOptions {
  20. RNNNavigationOptions* combinedOptions = [_presenter presentWithChildOptions:childOptions on:self];
  21. if ([self.parentViewController respondsToSelector:@selector(performOnChildWillAppear:)]) {
  22. [self.parentViewController performSelector:@selector(performOnChildWillAppear:) withObject:combinedOptions];
  23. }
  24. }
  25. - (UIInterfaceOrientationMask)supportedInterfaceOrientations {
  26. return self.selectedViewController.supportedInterfaceOrientations;
  27. }
  28. - (void)setSelectedIndexByComponentID:(NSString *)componentID {
  29. for (id child in self.childViewControllers) {
  30. UIViewController<RNNParentProtocol>* vc = child;
  31. if ([vc.layoutInfo.componentId isEqualToString:componentID]) {
  32. [self setSelectedIndex:[self.childViewControllers indexOfObject:child]];
  33. }
  34. }
  35. }
  36. - (void)setSelectedIndex:(NSUInteger)selectedIndex {
  37. _currentTabIndex = selectedIndex;
  38. [super setSelectedIndex:selectedIndex];
  39. }
  40. - (UIViewController *)getLeafViewController {
  41. return ((UIViewController<RNNParentProtocol>*)self.selectedViewController).getLeafViewController;
  42. }
  43. - (UIStatusBarStyle)preferredStatusBarStyle {
  44. return ((UIViewController<RNNParentProtocol>*)self.selectedViewController).preferredStatusBarStyle;
  45. }
  46. - (void)setViewControllers:(NSArray<__kindof UIViewController *> *)viewControllers {
  47. [super setViewControllers:viewControllers];
  48. }
  49. #pragma mark UITabBarControllerDelegate
  50. - (void)tabBarController:(UITabBarController *)tabBarController didSelectViewController:(UIViewController *)viewController {
  51. [_eventEmitter sendBottomTabSelected:@(tabBarController.selectedIndex) unselected:@(_currentTabIndex)];
  52. _currentTabIndex = tabBarController.selectedIndex;
  53. }
  54. @end