react-native-navigation的迁移库

RNNTabBarController.m 2.0KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  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. - (BOOL)isCustomTransitioned {
  36. return NO;
  37. }
  38. - (RNNOptions *)options {
  39. return nil;
  40. }
  41. - (void)mergeOptions:(NSDictionary *)options {
  42. [((UIViewController<RNNRootViewProtocol>*)self.selectedViewController) mergeOptions:options];
  43. }
  44. - (NSString *)componentId {
  45. return ((UIViewController<RNNRootViewProtocol>*)self.selectedViewController).componentId;
  46. }
  47. #pragma mark UITabBarControllerDelegate
  48. - (void)tabBarController:(UITabBarController *)tabBarController didSelectViewController:(UIViewController *)viewController {
  49. if (tabBarController.selectedIndex == _currentTabIndex) {
  50. [_eventEmitter sendOnNavigationEvent:@"bottomTabReselected" params:@{@"index": @(tabBarController.selectedIndex)}];
  51. } else {
  52. [_eventEmitter sendOnNavigationEvent:@"bottomTabSelected" params:@{@"index": @(tabBarController.selectedIndex)}];
  53. }
  54. _currentTabIndex = tabBarController.selectedIndex;
  55. }
  56. @end