react-native-navigation的迁移库

RNNTabBarController.m 2.4KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  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:(RNNOptions *)options {
  36. [((UIViewController<RNNRootViewProtocol>*)self.selectedViewController) mergeOptions:options];
  37. }
  38. - (void)waitForReactViewRender:(BOOL)wait perform:(RNNReactViewReadyCompletionBlock)readyBlock {
  39. [((UIViewController<RNNRootViewProtocol>*)self.selectedViewController) waitForReactViewRender:wait perform:readyBlock];
  40. }
  41. - (RNNNavigationOptions *)options {
  42. return [((UIViewController<RNNRootViewProtocol>*)self.selectedViewController) options];
  43. }
  44. - (UIViewController *)getLeafViewController {
  45. return ((UIViewController<RNNRootViewProtocol>*)self.selectedViewController);
  46. }
  47. - (NSString *)componentId {
  48. return ((UIViewController<RNNRootViewProtocol>*)self.selectedViewController).componentId;
  49. }
  50. - (UIStatusBarStyle)preferredStatusBarStyle {
  51. return ((UIViewController<RNNRootViewProtocol>*)self.selectedViewController).preferredStatusBarStyle;
  52. }
  53. #pragma mark UITabBarControllerDelegate
  54. - (void)tabBarController:(UITabBarController *)tabBarController didSelectViewController:(UIViewController *)viewController {
  55. [_eventEmitter sendOnNavigationEvent:@"bottomTabSelected" params:@{@"selectedTabIndex": @(tabBarController.selectedIndex), @"unselectedTabIndex": @(_currentTabIndex)}];
  56. _currentTabIndex = tabBarController.selectedIndex;
  57. }
  58. @end