react-native-navigation的迁移库

RNNTabBarController.m 2.1KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  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 ([vc.componentId isEqualToString:componentID]) {
  31. [self setSelectedIndex:[self.childViewControllers indexOfObject:child]];
  32. }
  33. }
  34. }
  35. - (void)mergeOptions:(NSDictionary *)options {
  36. [((UIViewController<RNNRootViewProtocol>*)self.selectedViewController) mergeOptions:options];
  37. }
  38. - (RNNNavigationOptions *)options {
  39. return [((UIViewController<RNNRootViewProtocol>*)self.selectedViewController) options];
  40. }
  41. - (NSString *)componentId {
  42. return ((UIViewController<RNNRootViewProtocol>*)self.selectedViewController).componentId;
  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 sendOnNavigationEvent:@"bottomTabSelected" params:@{@"selectedTabIndex": @(tabBarController.selectedIndex), @"unselectedTabIndex": @(_currentTabIndex)}];
  50. _currentTabIndex = tabBarController.selectedIndex;
  51. }
  52. @end