Browse Source

pop screen

Daniel Zlotin 7 years ago
parent
commit
9ec9bed7a1

+ 8
- 0
ios/RNNBridgeModule.m View File

28
 	[[vc navigationController]pushViewController:newVc animated:true];
28
 	[[vc navigationController]pushViewController:newVc animated:true];
29
 }
29
 }
30
 
30
 
31
+RCT_EXPORT_METHOD(pop:(NSString*)containerId)
32
+{
33
+	[self assertReady];
34
+	//TODO implement correctly
35
+	id vc = [UIApplication.sharedApplication.delegate.window.rootViewController childViewControllers][0];
36
+	[[vc navigationController] popViewControllerAnimated:true];
37
+}
38
+
31
 -(void)assertReady
39
 -(void)assertReady
32
 {
40
 {
33
 	if (!RNN.instance.isReadyToReceiveCommands) {
41
 	if (!RNN.instance.isReadyToReceiveCommands) {

+ 7
- 0
playground/e2e/app.test.js View File

31
     expect(elementByLabel('Alert')).toBeVisible();
31
     expect(elementByLabel('Alert')).toBeVisible();
32
     expect(elementByLabel('onStop!')).toBeVisible();
32
     expect(elementByLabel('onStop!')).toBeVisible();
33
   });
33
   });
34
+
35
+  it('pop screen', () => {
36
+    elementByLabel('Push').tap();
37
+    expect(elementByLabel('Pushed screen')).toBeVisible();
38
+    elementByLabel('Pop').tap();
39
+    expect(elementByLabel('React Native Navigation!')).toBeVisible();
40
+  });
34
 });
41
 });
35
 
42
 
36
 function elementByLabel(label) {
43
 function elementByLabel(label) {

+ 13
- 1
playground/src/containers/SimpleScreen.js View File

1
 import React, { Component } from 'react';
1
 import React, { Component } from 'react';
2
-import { View, Text } from 'react-native';
2
+import { View, Text, Button } from 'react-native';
3
+
4
+import Navigation from 'react-native-navigation';
3
 
5
 
4
 class SimpleScreen extends Component {
6
 class SimpleScreen extends Component {
7
+  constructor(props) {
8
+    super(props);
9
+    this.onClickPop = this.onClickPop.bind(this);
10
+  }
11
+
5
   render() {
12
   render() {
6
     return (
13
     return (
7
       <View style={styles.root}>
14
       <View style={styles.root}>
8
         <Text style={styles.h1}>{this.props.text || 'Simple Screen'}</Text>
15
         <Text style={styles.h1}>{this.props.text || 'Simple Screen'}</Text>
9
         {this.renderTextFromFunctionInProps()}
16
         {this.renderTextFromFunctionInProps()}
17
+        <Button title="Pop" onPress={this.onClickPop} />
10
       </View>
18
       </View>
11
     );
19
     );
12
   }
20
   }
19
       <Text style={styles.h1}>{this.props.myFunction()}</Text>
27
       <Text style={styles.h1}>{this.props.myFunction()}</Text>
20
     );
28
     );
21
   }
29
   }
30
+
31
+  onClickPop() {
32
+    Navigation.on(this.props.id).pop();
33
+  }
22
 }
34
 }
23
 export default SimpleScreen;
35
 export default SimpleScreen;
24
 
36
 

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

14
     this.nativeCommandsModule.push(onContainerId, layout);
14
     this.nativeCommandsModule.push(onContainerId, layout);
15
     return Promise.resolve(layout);
15
     return Promise.resolve(layout);
16
   }
16
   }
17
+
18
+  pop(containerId) {
19
+    this.nativeCommandsModule.pop(containerId);
20
+    return Promise.resolve(containerId);
21
+  }
17
 }
22
 }
18
 
23
 

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

7
   beforeEach(() => {
7
   beforeEach(() => {
8
     mockNativeModule = {
8
     mockNativeModule = {
9
       setRoot: jest.fn(),
9
       setRoot: jest.fn(),
10
-      push: jest.fn()
10
+      push: jest.fn(),
11
+      pop: jest.fn()
11
     };
12
     };
12
     NativeModules.RNNBridgeModule = mockNativeModule;
13
     NativeModules.RNNBridgeModule = mockNativeModule;
13
     uut = new NativeCommandsSender();
14
     uut = new NativeCommandsSender();
29
     expect(mockNativeModule.push).toHaveBeenCalledTimes(1);
30
     expect(mockNativeModule.push).toHaveBeenCalledTimes(1);
30
     expect(result).toBeDefined();
31
     expect(result).toBeDefined();
31
   });
32
   });
33
+
34
+  it('pop sends to native with containerId', async () => {
35
+    const result = await uut.pop('theContainerId');
36
+    expect(mockNativeModule.pop).toHaveBeenCalledTimes(1);
37
+    expect(result).toBeDefined();
38
+  });
32
 });
39
 });

+ 4
- 0
src/commands/ContainerCommands.js View File

14
     this.layoutTreeCrawler.crawl(layout);
14
     this.layoutTreeCrawler.crawl(layout);
15
     return this.nativeCommandsSender.push(this.containerId, layout);
15
     return this.nativeCommandsSender.push(this.containerId, layout);
16
   }
16
   }
17
+
18
+  pop() {
19
+    return this.nativeCommandsSender.pop(this.containerId);
20
+  }
17
 }
21
 }

+ 14
- 0
src/commands/ContainerCommands.test.js View File

44
       });
44
       });
45
     });
45
     });
46
   });
46
   });
47
+
48
+  describe('pop', () => {
49
+    it('pops a container, passing containerId', () => {
50
+      uut.pop();
51
+      expect(mockCommandsSender.pop).toHaveBeenCalledTimes(1);
52
+      expect(mockCommandsSender.pop).toHaveBeenCalledWith(containerId);
53
+    });
54
+
55
+    it('pop returns a promise that resolves to containerId', async () => {
56
+      mockCommandsSender.pop.mockReturnValue(Promise.resolve(containerId));
57
+      const result = await uut.pop();
58
+      expect(result).toEqual(containerId);
59
+    });
60
+  });
47
 });
61
 });