Joon Ho Cho 7 years ago
parent
commit
1586de0ef7
1 changed files with 20 additions and 2 deletions
  1. 20
    2
      lib/ios/RNNEventEmitter.m

+ 20
- 2
lib/ios/RNNEventEmitter.m View File

1
 #import "RNNEventEmitter.h"
1
 #import "RNNEventEmitter.h"
2
 
2
 
3
-@implementation RNNEventEmitter
3
+@implementation RNNEventEmitter {
4
+  NSInteger _appLaunchedListenerCount;
5
+  BOOL _appLaunchedEventDeferred;
6
+}
4
 
7
 
5
 RCT_EXPORT_MODULE();
8
 RCT_EXPORT_MODULE();
6
 
9
 
16
 # pragma mark public
19
 # pragma mark public
17
 
20
 
18
 -(void)sendOnAppLaunched {
21
 -(void)sendOnAppLaunched {
19
-	[self send:onAppLaunched body:nil];
22
+	if (_appLaunchedListenerCount > 0) {
23
+		[self send:onAppLaunched body:nil];
24
+	} else {
25
+		_appLaunchedEventDeferred = TRUE;
26
+	}
20
 }
27
 }
21
 
28
 
22
 -(void)sendContainerDidAppear:(NSString *)containerId {
29
 -(void)sendContainerDidAppear:(NSString *)containerId {
31
 	[self send:onNavigationButtonPressed body:@{@"containerId":containerId , @"buttonId": buttonId }];
38
 	[self send:onNavigationButtonPressed body:@{@"containerId":containerId , @"buttonId": buttonId }];
32
 }
39
 }
33
 
40
 
41
+- (void)addListener:(NSString *)eventName {
42
+	[super addListener:eventName];
43
+	if ([eventName isEqualToString:onAppLaunched]) {
44
+		_appLaunchedListenerCount++;
45
+		if (_appLaunchedEventDeferred) {
46
+			_appLaunchedEventDeferred = FALSE;
47
+			[self sendOnAppLaunched];
48
+		}
49
+	}
50
+}
51
+
34
 # pragma mark private
52
 # pragma mark private
35
 
53
 
36
 -(void)send:(NSString *)eventName body:(id)body {
54
 -(void)send:(NSString *)eventName body:(id)body {