1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071 |
-
- #import "RNNTabBarController.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;
- }
-
- - (void)performOnChildLoad:(RNNNavigationOptions *)childOptions {
- RNNNavigationOptions* combinedOptions = [_presenter presentWithChildOptions:childOptions on:self];
- if ([self.parentViewController respondsToSelector:@selector(performOnChildLoad:)]) {
- [self.parentViewController performSelector:@selector(performOnChildLoad:) withObject:combinedOptions];
- }
- }
-
- - (void)performOnChildWillAppear:(RNNNavigationOptions *)childOptions {
- RNNNavigationOptions* combinedOptions = [_presenter presentWithChildOptions:childOptions on:self];
- if ([self.parentViewController respondsToSelector:@selector(performOnChildWillAppear:)]) {
- [self.parentViewController performSelector:@selector(performOnChildWillAppear:) withObject:combinedOptions];
- }
- }
-
- - (UIInterfaceOrientationMask)supportedInterfaceOrientations {
- return self.selectedViewController.supportedInterfaceOrientations;
- }
-
- - (void)setSelectedIndexByComponentID:(NSString *)componentID {
- for (id child in self.childViewControllers) {
- UIViewController<RNNParentProtocol>* vc = child;
-
- if ([vc.layoutInfo.componentId isEqualToString:componentID]) {
- [self setSelectedIndex:[self.childViewControllers indexOfObject:child]];
- }
- }
- }
-
- - (void)setSelectedIndex:(NSUInteger)selectedIndex {
- _currentTabIndex = selectedIndex;
- [super setSelectedIndex:selectedIndex];
- }
-
- - (UIViewController *)getLeafViewController {
- return ((UIViewController<RNNParentProtocol>*)self.selectedViewController).getLeafViewController;
- }
-
- - (UIStatusBarStyle)preferredStatusBarStyle {
- return ((UIViewController<RNNParentProtocol>*)self.selectedViewController).preferredStatusBarStyle;
- }
-
- - (void)setViewControllers:(NSArray<__kindof UIViewController *> *)viewControllers {
- [super setViewControllers:viewControllers];
- }
-
- #pragma mark UITabBarControllerDelegate
-
- - (void)tabBarController:(UITabBarController *)tabBarController didSelectViewController:(UIViewController *)viewController {
- [_eventEmitter sendBottomTabSelected:@(tabBarController.selectedIndex) unselected:@(_currentTabIndex)];
- _currentTabIndex = tabBarController.selectedIndex;
- }
-
- @end
|