forked from wix/react-native-navigation
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathStackCommandsScreen.tsx
63 lines (58 loc) · 1.66 KB
/
StackCommandsScreen.tsx
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
import React from 'react';
import { Text } from 'react-native';
import { NavigationComponent, NavigationComponentProps } from 'react-native-navigation';
import Root from '../components/Root';
import Button from '../components/Button';
import Navigation from '../services/Navigation';
import Screens from './Screens';
import testIDs from '../testIDs';
const { PUSH_BTN, PUSH_PROMISE_RESULT, POP_PROMISE_RESULT } = testIDs;
interface State {
pushPromiseResult?: string;
popPromiseResult?: string;
}
export default class StackCommandsScreen extends NavigationComponent<
NavigationComponentProps,
State
> {
static options() {
return {
topBar: {
title: {
text: 'Stack Commands',
},
},
};
}
render() {
return (
<Root componentId={this.props.componentId}>
<Text testID={PUSH_PROMISE_RESULT}>{this.state?.pushPromiseResult || ''}</Text>
<Text testID={POP_PROMISE_RESULT}>{this.state?.popPromiseResult || ''}</Text>
<Button label="Push" testID={PUSH_BTN} onPress={this.push} />
</Root>
);
}
push = async () => {
return Navigation.push(this.props.componentId, {
component: {
id: 'ChildId',
name: Screens.Pushed,
},
})
.then(
(pushId) => new Promise<string>((resolve) => setTimeout(() => resolve(pushId), 100))
)
.then((pushId) => {
this.setState({
pushPromiseResult: `push promise resolved with: ${pushId}`,
});
return Navigation.pop('ChildId');
})
.then((popId) => {
this.setState({
popPromiseResult: `pop promise resolved with: ${popId}`,
});
});
};
}