Parcourir la source

receive generic params from native

Daniel Zlotin il y a 6 ans
Parent
révision
3c378d2cbf

+ 2
- 2
lib/ios/RNNEventEmitter.m Voir le fichier

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

+ 4
- 4
lib/src/adapters/NativeEventsReceiver.ts Voir le fichier

@@ -14,15 +14,15 @@ export class NativeEventsReceiver {
14 14
     return this.emitter.addListener('RNN.onAppLaunched', callback);
15 15
   }
16 16
 
17
-  registerComponentDidAppear(callback: (componentId: string, componentName: string) => void): EventSubscription {
17
+  registerComponentDidAppear(callback: (params) => void): EventSubscription {
18 18
     return this.emitter.addListener('RNN.componentDidAppear', callback);
19 19
   }
20 20
 
21
-  registerComponentDidDisappear(callback: (componentId: string, componentName: string) => void): EventSubscription {
21
+  registerComponentDidDisappear(callback: (params) => void): EventSubscription {
22 22
     return this.emitter.addListener('RNN.componentDidDisappear', callback);
23 23
   }
24 24
 
25
-  registerOnNavigationButtonPressed(callback: (componentId: string, buttonId: string) => void): EventSubscription {
26
-    return this.emitter.addListener('RNN.onNavigationButtonPressed', ({ componentId, buttonId }) => callback(componentId, buttonId));
25
+  registerOnNavigationButtonPressed(callback: (params) => void): EventSubscription {
26
+    return this.emitter.addListener('RNN.onNavigationButtonPressed', callback);
27 27
   }
28 28
 }

+ 9
- 3
lib/src/events/EventsRegistry.test.ts Voir le fichier

@@ -31,7 +31,9 @@ describe('EventsRegistry', () => {
31 31
 
32 32
     expect(result).toBe(subscription);
33 33
     expect(mockNativeEventsReceiver.registerComponentDidAppear).toHaveBeenCalledTimes(1);
34
-    expect(mockNativeEventsReceiver.registerComponentDidAppear).toHaveBeenCalledWith(cb);
34
+
35
+    mockNativeEventsReceiver.registerComponentDidAppear.mock.calls[0][0]({ componentId: 'theId' });
36
+    expect(cb).toHaveBeenCalledWith('theId', '');
35 37
   });
36 38
 
37 39
   it('exposes componentDidDisappear event', () => {
@@ -43,7 +45,9 @@ describe('EventsRegistry', () => {
43 45
 
44 46
     expect(result).toBe(subscription);
45 47
     expect(mockNativeEventsReceiver.registerComponentDidDisappear).toHaveBeenCalledTimes(1);
46
-    expect(mockNativeEventsReceiver.registerComponentDidDisappear).toHaveBeenCalledWith(cb);
48
+
49
+    mockNativeEventsReceiver.registerComponentDidDisappear.mock.calls[0][0]({ componentId: 'theId' });
50
+    expect(cb).toHaveBeenCalledWith('theId', '');
47 51
   });
48 52
 
49 53
   it('exposes onNavigationButtonPressed event', () => {
@@ -55,6 +59,8 @@ describe('EventsRegistry', () => {
55 59
 
56 60
     expect(result).toBe(subscription);
57 61
     expect(mockNativeEventsReceiver.registerOnNavigationButtonPressed).toHaveBeenCalledTimes(1);
58
-    expect(mockNativeEventsReceiver.registerOnNavigationButtonPressed).toHaveBeenCalledWith(cb);
62
+
63
+    mockNativeEventsReceiver.registerOnNavigationButtonPressed.mock.calls[0][0]({ componentId: 'theId', buttonId: 'theBtnId' });
64
+    expect(cb).toHaveBeenCalledWith('theId', 'theBtnId');
59 65
   });
60 66
 });

+ 3
- 3
lib/src/events/EventsRegistry.ts Voir le fichier

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