Browse Source

componentDidDisappear

Daniel Zlotin 6 years ago
parent
commit
40c47b754a

+ 1
- 5
lib/src/adapters/Element.tsx View File

@@ -4,11 +4,7 @@ import { requireNativeComponent } from 'react-native';
4 4
 
5 5
 let RNNElement: React.ComponentType<any>;
6 6
 
7
-export class Element extends React.Component<{
8
-  elementId: any;
9
-  resizeMode: any;
10
-}, any> {
11
-
7
+export class Element extends React.Component<{ elementId: any; resizeMode: any; }, any> {
12 8
   static propTypes = {
13 9
     elementId: PropTypes.string.isRequired,
14 10
     resizeMode: PropTypes.string

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

@@ -12,11 +12,37 @@ describe('EventsRegistry', () => {
12 12
 
13 13
   it('exposes appLaunch event', () => {
14 14
     const subscription = {};
15
-    mockNativeEventsReceiver.registerAppLaunched.mockReturnValueOnce(subscription);
16 15
     const cb = jest.fn();
16
+    mockNativeEventsReceiver.registerAppLaunched.mockReturnValueOnce(subscription);
17
+
17 18
     const result = uut.appLaunched(cb);
19
+
20
+    expect(result).toBe(subscription);
18 21
     expect(mockNativeEventsReceiver.registerAppLaunched).toHaveBeenCalledTimes(1);
19 22
     expect(mockNativeEventsReceiver.registerAppLaunched).toHaveBeenCalledWith(cb);
20
-    expect(subscription).toBe(result);
23
+  });
24
+
25
+  it('exposes componentDidAppear event', () => {
26
+    const subscription = {};
27
+    const cb = jest.fn();
28
+    mockNativeEventsReceiver.registerComponentDidAppear.mockReturnValueOnce(subscription);
29
+
30
+    const result = uut.componentDidAppear(cb);
31
+
32
+    expect(result).toBe(subscription);
33
+    expect(mockNativeEventsReceiver.registerComponentDidAppear).toHaveBeenCalledTimes(1);
34
+    expect(mockNativeEventsReceiver.registerComponentDidAppear).toHaveBeenCalledWith(cb);
35
+  });
36
+
37
+  it('exposes componentDidDisappear event', () => {
38
+    const subscription = {};
39
+    const cb = jest.fn();
40
+    mockNativeEventsReceiver.registerComponentDidDisappear.mockReturnValueOnce(subscription);
41
+
42
+    const result = uut.componentDidDisappear(cb);
43
+
44
+    expect(result).toBe(subscription);
45
+    expect(mockNativeEventsReceiver.registerComponentDidDisappear).toHaveBeenCalledTimes(1);
46
+    expect(mockNativeEventsReceiver.registerComponentDidDisappear).toHaveBeenCalledWith(cb);
21 47
   });
22 48
 });

+ 8
- 0
lib/src/events/EventsRegistry.ts View File

@@ -10,4 +10,12 @@ export class EventsRegistry {
10 10
   public appLaunched(callback): EventSubscription {
11 11
     return this.nativeEventsReceiver.registerAppLaunched(callback);
12 12
   }
13
+
14
+  public componentDidAppear(callback): EventSubscription {
15
+    return this.nativeEventsReceiver.registerComponentDidAppear(callback);
16
+  }
17
+
18
+  public componentDidDisappear(callback): EventSubscription {
19
+    return this.nativeEventsReceiver.registerComponentDidDisappear(callback);
20
+  }
13 21
 }