react-native-navigation的迁移库

RNNTabBarController.m 2.2KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  1. #import "RNNTabBarController.h"
  2. #import "RNNRootViewController.h"
  3. #define kTabBarHiddenDuration 0.3
  4. @implementation RNNTabBarController {
  5. NSUInteger _currentTabIndex;
  6. RNNEventEmitter *_eventEmitter;
  7. }
  8. - (instancetype)initWithEventEmitter:(id)eventEmitter {
  9. self = [super init];
  10. _eventEmitter = eventEmitter;
  11. self.delegate = self;
  12. return self;
  13. }
  14. - (UIInterfaceOrientationMask)supportedInterfaceOrientations {
  15. return self.selectedViewController.supportedInterfaceOrientations;
  16. }
  17. - (void)setTabBarHidden:(BOOL)hidden animated:(BOOL)animated {
  18. CGRect frame = self.tabBar.frame;
  19. CGFloat height = frame.size.height;
  20. CGFloat offsetY = (hidden ? self.view.frame.size.height : self.view.frame.size.height-height);
  21. frame.origin.y = offsetY;
  22. NSTimeInterval duration = animated ? kTabBarHiddenDuration : 0.0;
  23. [UIView animateWithDuration:duration animations:^{
  24. self.tabBar.frame = frame;
  25. }];
  26. }
  27. - (void)setSelectedIndexByComponentID:(NSString *)componentID {
  28. for (id child in self.childViewControllers) {
  29. RNNRootViewController* vc = child;
  30. if ([child isKindOfClass:[UINavigationController class]]) {
  31. vc = ((UINavigationController *)child).childViewControllers.firstObject;
  32. }
  33. if ([vc.componentId isEqualToString:componentID]) {
  34. [self setSelectedIndex:[self.childViewControllers indexOfObject:child]];
  35. }
  36. }
  37. }
  38. - (BOOL)isCustomTransitioned {
  39. return NO;
  40. }
  41. - (RNNOptions *)options {
  42. return nil;
  43. }
  44. - (void)mergeOptions:(NSDictionary *)options {
  45. [((UIViewController<RNNRootViewProtocol>*)self.selectedViewController) mergeOptions:options];
  46. }
  47. - (NSString *)componentId {
  48. return ((UIViewController<RNNRootViewProtocol>*)self.selectedViewController).componentId;
  49. }
  50. #pragma mark UITabBarControllerDelegate
  51. - (void)tabBarController:(UITabBarController *)tabBarController didSelectViewController:(UIViewController *)viewController {
  52. if (tabBarController.selectedIndex == _currentTabIndex) {
  53. [_eventEmitter sendOnNavigationEvent:@"bottomTabReselected" params:@{@"index": @(tabBarController.selectedIndex)}];
  54. } else {
  55. [_eventEmitter sendOnNavigationEvent:@"bottomTabSelected" params:@{@"index": @(tabBarController.selectedIndex)}];
  56. }
  57. _currentTabIndex = tabBarController.selectedIndex;
  58. }
  59. @end