Browse Source

bottomTab static events - #1078

yogevbd 6 years ago
parent
commit
0dc45525ea

+ 1
- 1
lib/ios/RNNControllerFactory.m View File

@@ -135,7 +135,7 @@
135 135
 }
136 136
 
137 137
 -(UIViewController<RNNRootViewProtocol> *)createTabs:(RNNLayoutNode*)node {
138
-	RNNTabBarController* vc = [[RNNTabBarController alloc] init];
138
+	RNNTabBarController* vc = [[RNNTabBarController alloc] initWithEventEmitter:_eventEmitter];
139 139
 	NSDictionary* options = node.data[@"options"];
140 140
 
141 141
 	NSMutableArray* controllers = [NSMutableArray new];

+ 1
- 1
lib/ios/RNNEventEmitter.m View File

@@ -15,7 +15,7 @@ static NSString* const onNavigationCommand	= @"RNN.onNavigationCommand";
15 15
 static NSString* const onNavigationEvent	= @"RNN.onNavigationEvent";
16 16
 
17 17
 -(NSArray<NSString *> *)supportedEvents {
18
-	return @[onAppLaunched, componentDidAppear, componentDidDisappear, onNavigationButtonPressed];
18
+	return @[onAppLaunched, componentDidAppear, componentDidDisappear, onNavigationButtonPressed, onNavigationCommand, onNavigationEvent];
19 19
 }
20 20
 
21 21
 # pragma mark public

+ 4
- 1
lib/ios/RNNTabBarController.h View File

@@ -1,8 +1,11 @@
1 1
 
2 2
 #import <UIKit/UIKit.h>
3 3
 #import "RNNRootViewProtocol.h"
4
+#import "RNNEventEmitter.h"
4 5
 
5
-@interface RNNTabBarController : UITabBarController <RNNRootViewProtocol>
6
+@interface RNNTabBarController : UITabBarController <RNNRootViewProtocol, UITabBarControllerDelegate>
7
+
8
+- (instancetype)initWithEventEmitter:(RNNEventEmitter*)eventEmitter;
6 9
 
7 10
 - (void)setTabBarHidden:(BOOL)hidden animated:(BOOL)animated;
8 11
 - (void)setSelectedIndexByComponentID:(NSString *)componentID;

+ 23
- 1
lib/ios/RNNTabBarController.m View File

@@ -3,7 +3,17 @@
3 3
 #import "RNNRootViewController.h"
4 4
 #define kTabBarHiddenDuration 0.3
5 5
 
6
-@implementation RNNTabBarController
6
+@implementation RNNTabBarController {
7
+	NSUInteger _currentTabIndex;
8
+	RNNEventEmitter *_eventEmitter;
9
+}
10
+
11
+- (instancetype)initWithEventEmitter:(id)eventEmitter {
12
+	self = [super init];
13
+	_eventEmitter = eventEmitter;
14
+	self.delegate = self;
15
+	return self;
16
+}
7 17
 
8 18
 - (UIInterfaceOrientationMask)supportedInterfaceOrientations {
9 19
 	return self.selectedViewController.supportedInterfaceOrientations;
@@ -49,4 +59,16 @@
49 59
 	return ((UIViewController<RNNRootViewProtocol>*)self.selectedViewController).componentId;
50 60
 }
51 61
 
62
+#pragma mark UITabBarControllerDelegate
63
+
64
+- (void)tabBarController:(UITabBarController *)tabBarController didSelectViewController:(UIViewController *)viewController {
65
+	if (tabBarController.selectedIndex == _currentTabIndex) {
66
+		[_eventEmitter sendOnNavigationEvent:@"bottomTabReselected" params:@{@"index": @(tabBarController.selectedIndex)}];
67
+	} else {
68
+		[_eventEmitter sendOnNavigationEvent:@"bottomTabSelected" params:@{@"index": @(tabBarController.selectedIndex)}];
69
+	}
70
+	
71
+	_currentTabIndex = tabBarController.selectedIndex;
72
+}
73
+
52 74
 @end