react-native-navigation的迁移库

RNNTabBarController.m 2.0KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  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. - (UIInterfaceOrientationMask)supportedInterfaceOrientations {
  14. return self.selectedViewController.supportedInterfaceOrientations;
  15. }
  16. - (void)setTabBarHidden:(BOOL)hidden animated:(BOOL)animated {
  17. CGRect frame = self.tabBar.frame;
  18. CGFloat height = frame.size.height;
  19. CGFloat offsetY = (hidden ? self.view.frame.size.height : self.view.frame.size.height-height);
  20. frame.origin.y = offsetY;
  21. NSTimeInterval duration = animated ? kTabBarHiddenDuration : 0.0;
  22. [UIView animateWithDuration:duration animations:^{
  23. self.tabBar.frame = frame;
  24. }];
  25. }
  26. - (void)setSelectedIndexByComponentID:(NSString *)componentID {
  27. for (id child in self.childViewControllers) {
  28. RNNRootViewController* vc = child;
  29. if ([vc.componentId isEqualToString:componentID]) {
  30. [self setSelectedIndex:[self.childViewControllers indexOfObject:child]];
  31. }
  32. }
  33. }
  34. - (void)setSelectedIndex:(NSUInteger)selectedIndex {
  35. _currentTabIndex = selectedIndex;
  36. [super setSelectedIndex:selectedIndex];
  37. }
  38. - (void)mergeOptions:(RNNOptions *)options {
  39. [self.getLeafViewController mergeOptions:options];
  40. }
  41. - (UIViewController *)getLeafViewController {
  42. return ((UIViewController<RNNRootViewProtocol>*)self.selectedViewController).getLeafViewController;
  43. }
  44. - (UIStatusBarStyle)preferredStatusBarStyle {
  45. return ((UIViewController<RNNRootViewProtocol>*)self.selectedViewController).preferredStatusBarStyle;
  46. }
  47. #pragma mark UITabBarControllerDelegate
  48. - (void)tabBarController:(UITabBarController *)tabBarController didSelectViewController:(UIViewController *)viewController {
  49. [_eventEmitter sendBottomTabSelected:@(tabBarController.selectedIndex) unselected:@(_currentTabIndex)];
  50. _currentTabIndex = tabBarController.selectedIndex;
  51. }
  52. @end