Quellcode durchsuchen

send params from native

Daniel Zlotin vor 7 Jahren
Ursprung
Commit
f69deccf0d

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

26
 	}
26
 	}
27
 
27
 
28
 	public void componentDidDisappear(String id, String componentName) {
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
 	public void componentDidAppear(String id, String componentName) {
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
     public void sendOnNavigationButtonPressed(String id, String buttonId) {
44
     public void sendOnNavigationButtonPressed(String id, String buttonId) {
46
 		WritableMap map = Arguments.createMap();
45
 		WritableMap map = Arguments.createMap();
57
 	private void emit(String eventName, WritableMap data) {
56
 	private void emit(String eventName, WritableMap data) {
58
 		emitter.emit(eventName, data);
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 Datei anzeigen

8
 
8
 
9
 -(void)sendOnAppLaunched;
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
 -(void)sendOnNavigationButtonPressed:(NSString*)componentId buttonId:(NSString*)buttonId;
15
 -(void)sendOnNavigationButtonPressed:(NSString*)componentId buttonId:(NSString*)buttonId;
16
 
16
 

+ 2
- 2
lib/ios/RNNEventEmitter.m Datei anzeigen

26
 	}
26
 	}
27
 }
27
 }
28
 
28
 
29
--(void)sendComponentDidAppear:(NSString *)componentId {
29
+-(void)sendComponentDidAppear:(NSString *)componentId componentName:(NSString *)componentName {
30
 	[self send:componentDidAppear body:@{@"componentId":componentId}];
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
 	[self send:componentDidDisappear body:@{@"componentId":componentId}];
34
 	[self send:componentDidDisappear body:@{@"componentId":componentId}];
35
 }
35
 }
36
 
36
 

+ 2
- 2
lib/ios/RNNRootViewController.m Datei anzeigen

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

+ 0
- 1
lib/src/events/ComponentEventsRegistry.ts Datei anzeigen

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

+ 4
- 4
lib/src/events/EventsRegistry.test.ts Datei anzeigen

32
     expect(result).toBe(subscription);
32
     expect(result).toBe(subscription);
33
     expect(mockNativeEventsReceiver.registerComponentDidAppear).toHaveBeenCalledTimes(1);
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
   it('exposes componentDidDisappear event', () => {
39
   it('exposes componentDidDisappear event', () => {
46
     expect(result).toBe(subscription);
46
     expect(result).toBe(subscription);
47
     expect(mockNativeEventsReceiver.registerComponentDidDisappear).toHaveBeenCalledTimes(1);
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
   it('exposes onNavigationButtonPressed event', () => {
53
   it('exposes onNavigationButtonPressed event', () => {

+ 2
- 2
lib/src/events/EventsRegistry.ts Datei anzeigen

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(({ componentId }) => callback(componentId, ''));
15
+    return this.nativeEventsReceiver.registerComponentDidAppear(({ componentId, componentName }) => callback(componentId, componentName));
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(({ componentId }) => callback(componentId, ''));
19
+    return this.nativeEventsReceiver.registerComponentDidDisappear(({ componentId, componentName }) => callback(componentId, componentName));
20
   }
20
   }
21
 
21
 
22
   public onNavigationButtonPressed(callback: (componentId: string, buttonId: string) => void): EventSubscription {
22
   public onNavigationButtonPressed(callback: (componentId: string, buttonId: string) => void): EventSubscription {