123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869 |
- #import "RNNBottomTabsController.h"
- #import "UITabBarController+RNNUtils.h"
-
- @implementation RNNBottomTabsController {
- NSUInteger _currentTabIndex;
- BottomTabsBaseAttacher* _bottomTabsAttacher;
- }
-
- - (instancetype)initWithLayoutInfo:(RNNLayoutInfo *)layoutInfo
- creator:(id<RNNComponentViewCreator>)creator
- options:(RNNNavigationOptions *)options
- defaultOptions:(RNNNavigationOptions *)defaultOptions
- presenter:(RNNBasePresenter *)presenter
- eventEmitter:(RNNEventEmitter *)eventEmitter
- childViewControllers:(NSArray *)childViewControllers
- bottomTabsAttacher:(BottomTabsBaseAttacher *)bottomTabsAttacher {
- self = [super initWithLayoutInfo:layoutInfo creator:creator options:options defaultOptions:defaultOptions presenter:presenter eventEmitter:eventEmitter childViewControllers:childViewControllers];
- _bottomTabsAttacher = bottomTabsAttacher;
- return self;
- }
-
- - (id<UITabBarControllerDelegate>)delegate {
- return self;
- }
-
- - (void)render {
- [_bottomTabsAttacher attach:self];
- }
-
- - (void)viewDidLayoutSubviews {
- [self.presenter viewDidLayoutSubviews];
- }
-
- - (UIViewController *)getCurrentChild {
- return self.selectedViewController;
- }
-
- - (CGFloat)getBottomTabsHeight {
- return self.tabBar.frame.size.height;
- }
-
- - (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];
- }
-
- - (UIStatusBarStyle)preferredStatusBarStyle {
- return [[self presenter] getStatusBarStyle:self.resolveOptions];
- }
-
- #pragma mark UITabBarControllerDelegate
-
- - (void)tabBarController:(UITabBarController *)tabBarController didSelectViewController:(UIViewController *)viewController {
- [self.eventEmitter sendBottomTabSelected:@(tabBarController.selectedIndex) unselected:@(_currentTabIndex)];
- _currentTabIndex = tabBarController.selectedIndex;
- }
-
- @end
|