Browse Source

send params from native

Daniel Zlotin 6 years ago
parent
commit
f69deccf0d

+ 10
- 15
lib/android/app/src/main/java/com/reactnativenavigation/react/NavigationEvent.java View File

@@ -26,21 +26,20 @@ public class NavigationEvent {
26 26
 	}
27 27
 
28 28
 	public void componentDidDisappear(String id, String componentName) {
29
-		emit(componentDidDisappear, id);
29
+		WritableMap map = Arguments.createMap();
30
+		map.putString("componentId", id);
31
+		map.putString("componentName", componentName);
32
+
33
+		emit(componentDidDisappear, map);
30 34
 	}
31 35
 
32 36
 	public void componentDidAppear(String id, String componentName) {
33
-		emit(componentDidAppear, id);
34
-	}
37
+		WritableMap map = Arguments.createMap();
38
+		map.putString("componentId", id);
39
+		map.putString("componentName", componentName);
35 40
 
36
-    @NonNull
37
-    private WritableMap getLifecycleEventData(String id, String componentName, String didAppear) {
38
-        WritableMap map = Arguments.createMap();
39
-        map.putString("componentId", id);
40
-        map.putString("componentName", componentName);
41
-        map.putString("event", didAppear);
42
-        return map;
43
-    }
41
+		emit(componentDidAppear, map);
42
+	}
44 43
 
45 44
     public void sendOnNavigationButtonPressed(String id, String buttonId) {
46 45
 		WritableMap map = Arguments.createMap();
@@ -57,8 +56,4 @@ public class NavigationEvent {
57 56
 	private void emit(String eventName, WritableMap data) {
58 57
 		emitter.emit(eventName, data);
59 58
 	}
60
-
61
-	private void emit(String eventName, String param) {
62
-		emitter.emit(eventName, param);
63
-	}
64 59
 }

+ 2
- 2
lib/ios/RNNEventEmitter.h View File

@@ -8,9 +8,9 @@
8 8
 
9 9
 -(void)sendOnAppLaunched;
10 10
 
11
--(void)sendComponentDidAppear:(NSString*)componentId;
11
+-(void)sendComponentDidAppear:(NSString*)componentId componentName:(NSString*)componentName;
12 12
 
13
--(void)sendComponentDidDisappear:(NSString*)componentId;
13
+-(void)sendComponentDidDisappear:(NSString*)componentId componentName:(NSString*)componentName;
14 14
 
15 15
 -(void)sendOnNavigationButtonPressed:(NSString*)componentId buttonId:(NSString*)buttonId;
16 16
 

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

@@ -26,11 +26,11 @@ static NSString* const onNavigationButtonPressed	= @"RNN.onNavigationButtonPress
26 26
 	}
27 27
 }
28 28
 
29
--(void)sendComponentDidAppear:(NSString *)componentId {
29
+-(void)sendComponentDidAppear:(NSString *)componentId componentName:(NSString *)componentName {
30 30
 	[self send:componentDidAppear body:@{@"componentId":componentId}];
31 31
 }
32 32
 
33
--(void)sendComponentDidDisappear:(NSString *)componentId {
33
+-(void)sendComponentDidDisappear:(NSString *)componentId componentName:(NSString *)componentName{
34 34
 	[self send:componentDidDisappear body:@{@"componentId":componentId}];
35 35
 }
36 36
 

+ 2
- 2
lib/ios/RNNRootViewController.m View File

@@ -52,7 +52,7 @@
52 52
 
53 53
 -(void)viewDidAppear:(BOOL)animated {
54 54
 	[super viewDidAppear:animated];
55
-	[self.eventEmitter sendComponentDidAppear:self.componentId];
55
+	[self.eventEmitter sendComponentDidAppear:self.componentId componentName:self.componentName];
56 56
 }
57 57
 
58 58
 - (void)viewWillDisappear:(BOOL)animated {
@@ -61,7 +61,7 @@
61 61
 
62 62
 -(void)viewDidDisappear:(BOOL)animated {
63 63
 	[super viewDidDisappear:animated];
64
-	[self.eventEmitter sendComponentDidDisappear:self.componentId];
64
+	[self.eventEmitter sendComponentDidDisappear:self.componentId componentName:self.componentName];
65 65
 }
66 66
 
67 67
 - (void)viewDidLoad {

+ 0
- 1
lib/src/events/ComponentEventsRegistry.ts View File

@@ -29,7 +29,6 @@ export class ComponentEventsRegistry {
29 29
   }
30 30
 
31 31
   private onNavigationButtonPressed(componentId: string, buttonId: string) {
32
-    console.log(componentId, buttonId); //tslint:disable-line
33 32
     const componentRef = this.store.getRefForId(componentId);
34 33
     if (componentRef && componentRef.onNavigationButtonPressed) {
35 34
       componentRef.onNavigationButtonPressed(buttonId);

+ 4
- 4
lib/src/events/EventsRegistry.test.ts View File

@@ -32,8 +32,8 @@ describe('EventsRegistry', () => {
32 32
     expect(result).toBe(subscription);
33 33
     expect(mockNativeEventsReceiver.registerComponentDidAppear).toHaveBeenCalledTimes(1);
34 34
 
35
-    mockNativeEventsReceiver.registerComponentDidAppear.mock.calls[0][0]({ componentId: 'theId' });
36
-    expect(cb).toHaveBeenCalledWith('theId', '');
35
+    mockNativeEventsReceiver.registerComponentDidAppear.mock.calls[0][0]({ componentId: 'theId', componentName: 'theName' });
36
+    expect(cb).toHaveBeenCalledWith('theId', 'theName');
37 37
   });
38 38
 
39 39
   it('exposes componentDidDisappear event', () => {
@@ -46,8 +46,8 @@ describe('EventsRegistry', () => {
46 46
     expect(result).toBe(subscription);
47 47
     expect(mockNativeEventsReceiver.registerComponentDidDisappear).toHaveBeenCalledTimes(1);
48 48
 
49
-    mockNativeEventsReceiver.registerComponentDidDisappear.mock.calls[0][0]({ componentId: 'theId' });
50
-    expect(cb).toHaveBeenCalledWith('theId', '');
49
+    mockNativeEventsReceiver.registerComponentDidDisappear.mock.calls[0][0]({ componentId: 'theId', componentName: 'theName' });
50
+    expect(cb).toHaveBeenCalledWith('theId', 'theName');
51 51
   });
52 52
 
53 53
   it('exposes onNavigationButtonPressed event', () => {

+ 2
- 2
lib/src/events/EventsRegistry.ts View File

@@ -12,11 +12,11 @@ export class EventsRegistry {
12 12
   }
13 13
 
14 14
   public componentDidAppear(callback: (componentId: string, componentName: string) => void): EventSubscription {
15
-    return this.nativeEventsReceiver.registerComponentDidAppear(({ componentId }) => callback(componentId, ''));
15
+    return this.nativeEventsReceiver.registerComponentDidAppear(({ componentId, componentName }) => callback(componentId, componentName));
16 16
   }
17 17
 
18 18
   public componentDidDisappear(callback: (componentId: string, componentName: string) => void): EventSubscription {
19
-    return this.nativeEventsReceiver.registerComponentDidDisappear(({ componentId }) => callback(componentId, ''));
19
+    return this.nativeEventsReceiver.registerComponentDidDisappear(({ componentId, componentName }) => callback(componentId, componentName));
20 20
   }
21 21
 
22 22
   public onNavigationButtonPressed(callback: (componentId: string, buttonId: string) => void): EventSubscription {