Browse Source

pop screen

Daniel Zlotin 7 years ago
parent
commit
9ec9bed7a1

+ 8
- 0
ios/RNNBridgeModule.m View File

@@ -28,6 +28,14 @@ RCT_EXPORT_METHOD(push:(NSString*)containerId layout:(NSDictionary*)layout)
28 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 39
 -(void)assertReady
32 40
 {
33 41
 	if (!RNN.instance.isReadyToReceiveCommands) {

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

@@ -31,6 +31,13 @@ describe('app', () => {
31 31
     expect(elementByLabel('Alert')).toBeVisible();
32 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 43
 function elementByLabel(label) {

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

@@ -1,12 +1,20 @@
1 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 6
 class SimpleScreen extends Component {
7
+  constructor(props) {
8
+    super(props);
9
+    this.onClickPop = this.onClickPop.bind(this);
10
+  }
11
+
5 12
   render() {
6 13
     return (
7 14
       <View style={styles.root}>
8 15
         <Text style={styles.h1}>{this.props.text || 'Simple Screen'}</Text>
9 16
         {this.renderTextFromFunctionInProps()}
17
+        <Button title="Pop" onPress={this.onClickPop} />
10 18
       </View>
11 19
     );
12 20
   }
@@ -19,6 +27,10 @@ class SimpleScreen extends Component {
19 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 35
 export default SimpleScreen;
24 36
 

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

@@ -14,5 +14,10 @@ export default class NativeCommandsSender {
14 14
     this.nativeCommandsModule.push(onContainerId, layout);
15 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,7 +7,8 @@ describe('NativeCommandsSender', () => {
7 7
   beforeEach(() => {
8 8
     mockNativeModule = {
9 9
       setRoot: jest.fn(),
10
-      push: jest.fn()
10
+      push: jest.fn(),
11
+      pop: jest.fn()
11 12
     };
12 13
     NativeModules.RNNBridgeModule = mockNativeModule;
13 14
     uut = new NativeCommandsSender();
@@ -29,4 +30,10 @@ describe('NativeCommandsSender', () => {
29 30
     expect(mockNativeModule.push).toHaveBeenCalledTimes(1);
30 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,4 +14,8 @@ export default class ContainerCommands {
14 14
     this.layoutTreeCrawler.crawl(layout);
15 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,4 +44,18 @@ describe('ContainerCommands', () => {
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
 });