1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677 |
-
- #import "RNNTabBarController.h"
- #import "RNNRootViewController.h"
- #define kTabBarHiddenDuration 0.3
-
- @implementation RNNTabBarController {
- NSUInteger _currentTabIndex;
- RNNEventEmitter *_eventEmitter;
- }
-
- - (instancetype)initWithEventEmitter:(id)eventEmitter {
- self = [super init];
- _eventEmitter = eventEmitter;
- self.delegate = self;
- return self;
- }
-
- - (UIInterfaceOrientationMask)supportedInterfaceOrientations {
- return self.selectedViewController.supportedInterfaceOrientations;
- }
-
- - (void)setTabBarHidden:(BOOL)hidden animated:(BOOL)animated {
- CGRect frame = self.tabBar.frame;
- CGFloat height = frame.size.height;
- CGFloat offsetY = (hidden ? self.view.frame.size.height : self.view.frame.size.height-height);
- frame.origin.y = offsetY;
- NSTimeInterval duration = animated ? kTabBarHiddenDuration : 0.0;
-
- [UIView animateWithDuration:duration animations:^{
- self.tabBar.frame = frame;
- }];
- }
-
- - (void)setSelectedIndexByComponentID:(NSString *)componentID {
- for (id child in self.childViewControllers) {
- RNNRootViewController* vc = child;
-
- if ([vc.componentId isEqualToString:componentID]) {
- [self setSelectedIndex:[self.childViewControllers indexOfObject:child]];
- }
- }
- }
-
- - (void)mergeOptions:(RNNOptions *)options {
- [((UIViewController<RNNRootViewProtocol>*)self.selectedViewController) mergeOptions:options];
- }
-
- - (void)waitForReactViewRender:(BOOL)wait perform:(RNNReactViewReadyCompletionBlock)readyBlock {
- [((UIViewController<RNNRootViewProtocol>*)self.selectedViewController) waitForReactViewRender:wait perform:readyBlock];
- }
-
- - (RNNNavigationOptions *)options {
- return [((UIViewController<RNNRootViewProtocol>*)self.selectedViewController) options];
- }
-
- - (UIViewController *)getLeafViewController {
- return ((UIViewController<RNNRootViewProtocol>*)self.selectedViewController);
- }
-
- - (NSString *)componentId {
- return ((UIViewController<RNNRootViewProtocol>*)self.selectedViewController).componentId;
- }
-
- - (UIStatusBarStyle)preferredStatusBarStyle {
- return ((UIViewController<RNNRootViewProtocol>*)self.selectedViewController).preferredStatusBarStyle;
- }
-
- #pragma mark UITabBarControllerDelegate
-
- - (void)tabBarController:(UITabBarController *)tabBarController didSelectViewController:(UIViewController *)viewController {
- [_eventEmitter sendOnNavigationEvent:@"bottomTabSelected" params:@{@"selectedTabIndex": @(tabBarController.selectedIndex), @"unselectedTabIndex": @(_currentTabIndex)}];
-
- _currentTabIndex = tabBarController.selectedIndex;
- }
-
- @end
|