Browse Source

receive generic params from native

Daniel Zlotin 6 years ago
parent
commit
3c378d2cbf

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

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

+ 4
- 4
lib/src/adapters/NativeEventsReceiver.ts View File

14
     return this.emitter.addListener('RNN.onAppLaunched', callback);
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
     return this.emitter.addListener('RNN.componentDidAppear', callback);
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
     return this.emitter.addListener('RNN.componentDidDisappear', callback);
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 View File

31
 
31
 
32
     expect(result).toBe(subscription);
32
     expect(result).toBe(subscription);
33
     expect(mockNativeEventsReceiver.registerComponentDidAppear).toHaveBeenCalledTimes(1);
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
   it('exposes componentDidDisappear event', () => {
39
   it('exposes componentDidDisappear event', () => {
43
 
45
 
44
     expect(result).toBe(subscription);
46
     expect(result).toBe(subscription);
45
     expect(mockNativeEventsReceiver.registerComponentDidDisappear).toHaveBeenCalledTimes(1);
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
   it('exposes onNavigationButtonPressed event', () => {
53
   it('exposes onNavigationButtonPressed event', () => {
55
 
59
 
56
     expect(result).toBe(subscription);
60
     expect(result).toBe(subscription);
57
     expect(mockNativeEventsReceiver.registerOnNavigationButtonPressed).toHaveBeenCalledTimes(1);
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 View File

12
   }
12
   }
13
 
13
 
14
   public componentDidAppear(callback: (componentId: string, componentName: string) => void): EventSubscription {
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
   public componentDidDisappear(callback: (componentId: string, componentName: string) => void): EventSubscription {
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
   public onNavigationButtonPressed(callback: (componentId: string, buttonId: string) => void): EventSubscription {
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
 }