react-native-navigation的迁移库

RNNTabBarController.m 1.8KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  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)mergeOptions:(RNNOptions *)options {
  35. [self.getLeafViewController mergeOptions:options];
  36. }
  37. - (UIViewController *)getLeafViewController {
  38. return ((UIViewController<RNNRootViewProtocol>*)self.selectedViewController).getLeafViewController;
  39. }
  40. - (UIStatusBarStyle)preferredStatusBarStyle {
  41. return ((UIViewController<RNNRootViewProtocol>*)self.selectedViewController).preferredStatusBarStyle;
  42. }
  43. #pragma mark UITabBarControllerDelegate
  44. - (void)tabBarController:(UITabBarController *)tabBarController didSelectViewController:(UIViewController *)viewController {
  45. [_eventEmitter sendBottomTabSelected:@(tabBarController.selectedIndex) unselected:@(_currentTabIndex)];
  46. _currentTabIndex = tabBarController.selectedIndex;
  47. }
  48. @end