Sfoglia il codice sorgente

js:prepare dismissModal api

Daniel Zlotin 8 anni fa
parent
commit
a70a8eb089

+ 5
- 0
playground/src/containers/SimpleScreen.js Vedi File

8
     super(props);
8
     super(props);
9
     this.onClickPop = this.onClickPop.bind(this);
9
     this.onClickPop = this.onClickPop.bind(this);
10
     this.onClickPush = this.onClickPush.bind(this);
10
     this.onClickPush = this.onClickPush.bind(this);
11
+    this.onClickDismissModal = this.onClickDismissModal.bind(this);
11
   }
12
   }
12
 
13
 
13
   render() {
14
   render() {
18
         {this.renderTextFromFunctionInProps()}
19
         {this.renderTextFromFunctionInProps()}
19
         <Button title="Push" onPress={this.onClickPush} />
20
         <Button title="Push" onPress={this.onClickPush} />
20
         <Button title="Pop" onPress={this.onClickPop} />
21
         <Button title="Pop" onPress={this.onClickPop} />
22
+        <Button title="Dismiss Modal" onPress={this.onClickDismissModal} />
21
       </View>
23
       </View>
22
     );
24
     );
23
   }
25
   }
44
     });
46
     });
45
   }
47
   }
46
 
48
 
49
+  onClickDismissModal() {
50
+    Navigation.dismissModal(this.props.id);
51
+  }
47
 }
52
 }
48
 export default SimpleScreen;
53
 export default SimpleScreen;
49
 
54
 

+ 4
- 0
src/Navigation.js Vedi File

38
     return this.appCommands.showModal(params);
38
     return this.appCommands.showModal(params);
39
   }
39
   }
40
 
40
 
41
+  dismissModal(id) {
42
+    return this.appCommands.dismissModal(id);
43
+  }
44
+
41
   events() {
45
   events() {
42
     return this.publicEventsRegistry;
46
     return this.publicEventsRegistry;
43
   }
47
   }

+ 9
- 0
src/Navigation.test.js Vedi File

39
     expect(Navigation.appCommands.showModal).toHaveBeenCalledWith(params);
39
     expect(Navigation.appCommands.showModal).toHaveBeenCalledWith(params);
40
   });
40
   });
41
 
41
 
42
+  it('dismissModal delegates to AppCommands', async () => {
43
+    Navigation.appCommands.dismissModal.mockReturnValue(Promise.resolve('result'));
44
+    const params = {};
45
+    const result = await Navigation.dismissModal(params);
46
+    expect(result).toEqual('result');
47
+    expect(Navigation.appCommands.dismissModal).toHaveBeenCalledTimes(1);
48
+    expect(Navigation.appCommands.dismissModal).toHaveBeenCalledWith(params);
49
+  });
50
+
42
   it('events return public events', () => {
51
   it('events return public events', () => {
43
     const cb = jest.fn();
52
     const cb = jest.fn();
44
     Navigation.events().onAppLaunched(cb);
53
     Navigation.events().onAppLaunched(cb);

+ 5
- 0
src/adapters/NativeCommandsSender.js Vedi File

24
     this.nativeCommandsModule.showModal(layout);
24
     this.nativeCommandsModule.showModal(layout);
25
     return Promise.resolve(layout);
25
     return Promise.resolve(layout);
26
   }
26
   }
27
+
28
+  dismissModal(id) {
29
+    this.nativeCommandsModule.dismissModal(id);
30
+    return Promise.resolve(id);
31
+  }
27
 }
32
 }
28
 
33
 

+ 8
- 1
src/adapters/NativeCommandsSender.test.js Vedi File

9
       setRoot: jest.fn(),
9
       setRoot: jest.fn(),
10
       push: jest.fn(),
10
       push: jest.fn(),
11
       pop: jest.fn(),
11
       pop: jest.fn(),
12
-      showModal: jest.fn()
12
+      showModal: jest.fn(),
13
+      dismissModal: jest.fn()
13
     };
14
     };
14
     NativeModules.RNNBridgeModule = mockNativeModule;
15
     NativeModules.RNNBridgeModule = mockNativeModule;
15
     uut = new NativeCommandsSender();
16
     uut = new NativeCommandsSender();
43
     expect(mockNativeModule.showModal).toHaveBeenCalledTimes(1);
44
     expect(mockNativeModule.showModal).toHaveBeenCalledTimes(1);
44
     expect(result).toBeDefined();
45
     expect(result).toBeDefined();
45
   });
46
   });
47
+
48
+  it('dismissModal', async () => {
49
+    const result = await uut.dismissModal('id');
50
+    expect(mockNativeModule.dismissModal).toHaveBeenCalledTimes(1);
51
+    expect(result).toEqual('id');
52
+  });
46
 });
53
 });

+ 4
- 0
src/commands/AppCommands.js Vedi File

20
     this.layoutTreeCrawler.crawl(layout);
20
     this.layoutTreeCrawler.crawl(layout);
21
     return this.nativeCommandsSender.showModal(layout);
21
     return this.nativeCommandsSender.showModal(layout);
22
   }
22
   }
23
+
24
+  dismissModal(id) {
25
+    return this.nativeCommandsSender.dismissModal(id);
26
+  }
23
 }
27
 }
24
 
28
 

+ 14
- 0
src/commands/AppCommands.test.js Vedi File

100
       expect(result).toEqual('the resolved layout');
100
       expect(result).toEqual('the resolved layout');
101
     });
101
     });
102
   });
102
   });
103
+
104
+  describe('dismissModal', () => {
105
+    it('sends command to native', () => {
106
+      uut.dismissModal('myUniqueId');
107
+      expect(mockCommandsSender.dismissModal).toHaveBeenCalledTimes(1);
108
+      expect(mockCommandsSender.dismissModal).toHaveBeenCalledWith('myUniqueId');
109
+    });
110
+
111
+    it('returns a promise with the id', async () => {
112
+      mockCommandsSender.dismissModal.mockReturnValue(Promise.resolve('the id'));
113
+      const result = await uut.dismissModal('myUniqueId');
114
+      expect(result).toEqual('the id');
115
+    });
116
+  });
103
 });
117
 });