123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102 |
- #import "RNNTabBarController.h"
-
- @implementation RNNTabBarController {
- NSUInteger _currentTabIndex;
- }
-
- - (instancetype)initWithLayoutInfo:(RNNLayoutInfo *)layoutInfo
- childViewControllers:(NSArray *)childViewControllers
- options:(RNNNavigationOptions *)options
- defaultOptions:(RNNNavigationOptions *)defaultOptions
- presenter:(RNNTabBarPresenter *)presenter
- eventEmitter:(RNNEventEmitter *)eventEmitter {
- self = [self initWithLayoutInfo:layoutInfo childViewControllers:childViewControllers options:options defaultOptions:defaultOptions presenter:presenter];
-
- _eventEmitter = eventEmitter;
-
- return self;
- }
-
- - (instancetype)initWithLayoutInfo:(RNNLayoutInfo *)layoutInfo
- childViewControllers:(NSArray *)childViewControllers
- options:(RNNNavigationOptions *)options
- defaultOptions:(RNNNavigationOptions *)defaultOptions
- presenter:(RNNTabBarPresenter *)presenter {
- self = [super init];
-
- self.delegate = self;
- self.options = options;
- self.defaultOptions = defaultOptions;
- self.layoutInfo = layoutInfo;
- self.presenter = presenter;
- [self.presenter bindViewController:self];
- [self setViewControllers:childViewControllers];
- [self.presenter applyOptionsOnInit:self.options];
-
- return self;
- }
-
- - (void)willMoveToParentViewController:(UIViewController *)parent {
- if (parent) {
- [_presenter applyOptionsOnWillMoveToParentViewController:self.resolveOptions];
- }
- }
-
- - (void)onChildWillAppear {
- [_presenter applyOptions:self.resolveOptions];
- [((UIViewController<RNNParentProtocol> *)self.parentViewController) onChildWillAppear];
- }
-
- - (RNNNavigationOptions *)resolveOptions {
- return [(RNNNavigationOptions *)[self.getCurrentChild.resolveOptions.copy mergeOptions:self.options] withDefault:self.defaultOptions];
- }
-
- - (void)mergeOptions:(RNNNavigationOptions *)options {
- [_presenter mergeOptions:options currentOptions:self.options defaultOptions:self.defaultOptions];
- [((UIViewController<RNNLayoutProtocol> *)self.parentViewController) mergeOptions:options];
- }
-
- - (void)overrideOptions:(RNNNavigationOptions *)options {
- [self.options overrideOptions:options];
- }
-
- - (UIInterfaceOrientationMask)supportedInterfaceOrientations {
- return self.selectedViewController.supportedInterfaceOrientations;
- }
-
- - (void)setSelectedIndexByComponentID:(NSString *)componentID {
- for (id child in self.childViewControllers) {
- UIViewController<RNNLayoutProtocol>* vc = child;
-
- if ([vc conformsToProtocol:@protocol(RNNLayoutProtocol)] && [vc.layoutInfo.componentId isEqualToString:componentID]) {
- [self setSelectedIndex:[self.childViewControllers indexOfObject:child]];
- }
- }
- }
-
- - (void)setSelectedIndex:(NSUInteger)selectedIndex {
- _currentTabIndex = selectedIndex;
- [super setSelectedIndex:selectedIndex];
- }
-
- - (UIViewController *)getCurrentChild {
- return self.selectedViewController;
- }
-
- - (UIViewController<RNNLeafProtocol> *)getCurrentLeaf {
- return [[self getCurrentChild] getCurrentLeaf];
- }
-
- - (UIStatusBarStyle)preferredStatusBarStyle {
- return ((UIViewController<RNNParentProtocol>*)self.selectedViewController).preferredStatusBarStyle;
- }
-
- #pragma mark UITabBarControllerDelegate
-
- - (void)tabBarController:(UITabBarController *)tabBarController didSelectViewController:(UIViewController *)viewController {
- [_eventEmitter sendBottomTabSelected:@(tabBarController.selectedIndex) unselected:@(_currentTabIndex)];
- _currentTabIndex = tabBarController.selectedIndex;
- }
-
- @end
|