This repository was archived by the owner on Feb 25, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 189
Expand file tree
/
Copy pathSimpleStack.js
More file actions
156 lines (141 loc) · 3.23 KB
/
Copy pathSimpleStack.js
File metadata and controls
156 lines (141 loc) · 3.23 KB
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
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
import * as React from 'react';
import { Dimensions, Button, View, Text } from 'react-native';
import { withNavigation } from '@react-navigation/core';
import { createStackNavigator } from 'react-navigation-stack';
const Buttons = withNavigation(props => (
<React.Fragment>
<Button
title="Go to Details"
onPress={() => props.navigation.navigate('Details')}
/>
<Button
title="Replace with List"
onPress={() => props.navigation.replace('List')}
/>
<Button
title="Go and then go to details quick"
onPress={() => {
props.navigation.pop();
setTimeout(() => {
props.navigation.navigate('Details');
}, 100);
}}
/>
<Button
title="Go to Headerless"
onPress={() => props.navigation.navigate('Headerless')}
/>
<Button title="Go back" onPress={() => props.navigation.goBack()} />
<Button
title="Go back quick"
onPress={() => {
props.navigation.pop();
setTimeout(() => {
props.navigation.pop();
}, 100);
}}
/>
<Button
title="Go back to all examples"
onPress={() => props.navigation.navigate('Home')}
/>
</React.Fragment>
));
class ListScreen extends React.Component {
static navigationOptions = {
title: 'List',
};
componentDidMount() {
console.log('ListScreen didMount');
}
componentWillUnmount() {
console.log('ListScreen willUnmount');
}
render() {
return (
<View
style={{
flex: 1,
alignItems: 'center',
justifyContent: 'center',
backgroundColor: '#fff',
}}
>
<Text>List Screen</Text>
<Text>A list may go here</Text>
<Buttons />
</View>
);
}
}
class DetailsScreen extends React.Component {
static navigationOptions = {
title: 'Details',
gestureResponseDistance: {
horizontal: Dimensions.get('window').width,
},
};
componentDidMount() {
console.log('DetailsScreen didMount');
}
componentWillUnmount() {
console.log('DetailsScreen willUnmount');
}
render() {
return (
<View
style={{
flex: 1,
alignItems: 'center',
justifyContent: 'center',
backgroundColor: '#fff',
}}
>
<Text>Details Screen</Text>
<Button title="Go back in 2s" onPress={this._goBackInTwoSeconds} />
<Buttons />
</View>
);
}
_goBackInTwoSeconds = () => {
setTimeout(() => {
this.props.navigation.goBack();
}, 2000);
};
}
class HeaderlessScreen extends React.Component {
static navigationOptions = {
header: null,
};
componentDidMount() {
console.log('HeaderlessScreen didMount');
}
componentWillUnmount() {
console.log('HeaderlessScreen willUnmount');
}
render() {
return (
<View
style={{
flex: 1,
alignItems: 'center',
justifyContent: 'center',
backgroundColor: '#fff',
}}
>
<Text>Headerless Screen</Text>
<Buttons />
</View>
);
}
}
export default createStackNavigator(
{
List: ListScreen,
Details: DetailsScreen,
Headerless: HeaderlessScreen,
},
{
initialRouteName: 'List',
}
);