Skip to content

Commit 8dd9c6b

Browse files
author
andyboythekid
committed
update examples
1 parent 9bbc2d2 commit 8dd9c6b

File tree

2 files changed

+232
-260
lines changed

2 files changed

+232
-260
lines changed

example/src/entry-example.tsx

Lines changed: 161 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,161 @@
1+
import React, { useState } from 'react';
2+
import { View, Text, StyleSheet } from 'react-native';
3+
import {
4+
Navigator,
5+
Tabs,
6+
Link,
7+
NavigatorScreen,
8+
Headers,
9+
Header,
10+
} from 'react-navigation-library';
11+
import { TextInput, BorderlessButton } from 'react-native-gesture-handler';
12+
13+
function Entry({ }: NavigatorScreen) {
14+
return (
15+
<Navigator routes={['signup', '/', 'login']}>
16+
{({ navigate, state }: any) => (
17+
<>
18+
<Headers>
19+
<Header>
20+
<Text style={styles.title}>Signup</Text>
21+
</Header>
22+
<Header>
23+
<Text style={styles.title}>Select Option</Text>
24+
</Header>
25+
<Header>
26+
<Text style={styles.title}>Login</Text>
27+
</Header>
28+
</Headers>
29+
30+
<Tabs>
31+
<Signup navigate={navigate} />
32+
<SelectionScreen email={state.email} />
33+
<Login navigate={navigate} />
34+
</Tabs>
35+
</>
36+
)}
37+
</Navigator>
38+
);
39+
}
40+
41+
function Signup({ navigate }: any) {
42+
function handleSubmit(email: string, password: string) {
43+
// return to selection screen
44+
navigate('./', { email, password });
45+
}
46+
47+
return (
48+
<Screen background="coral">
49+
<Form title="Signup" onSubmit={handleSubmit} />
50+
</Screen>
51+
);
52+
}
53+
54+
function Login({ navigate }: any) {
55+
function handleSubmit(email: string, password: string) {
56+
// return to selection screen
57+
navigate('./', { email, password });
58+
}
59+
60+
return (
61+
<Screen background="cadetblue">
62+
<Form title="Login" onSubmit={handleSubmit} />
63+
</Screen>
64+
);
65+
}
66+
67+
function SelectionScreen({ email = '' }: any) {
68+
return (
69+
<Screen background="aquamarine">
70+
{Boolean(email) && (
71+
<Text
72+
style={[styles.title, { flex: 0, marginVertical: 20 }]}
73+
>{`Thanks ${email}!`}</Text>
74+
)}
75+
76+
<View style={{ flex: 1, alignItems: 'center' }}>
77+
<Link to="signup" style={styles.button}>
78+
<Text>Signup</Text>
79+
</Link>
80+
<Link to="login" style={styles.button}>
81+
<Text>Login</Text>
82+
</Link>
83+
</View>
84+
</Screen>
85+
);
86+
}
87+
88+
function Form({ onSubmit }: any) {
89+
const [email, setEmail] = useState('');
90+
const [password, setPassword] = useState('');
91+
92+
function handleSubmit() {
93+
onSubmit(email, password);
94+
}
95+
96+
return (
97+
<Screen>
98+
<View style={{ flex: 1, marginTop: 20, paddingHorizontal: 30 }}>
99+
<TextInput
100+
placeholder="Enter email"
101+
textContentType="emailAddress"
102+
autoCapitalize="none"
103+
autoCompleteType="email"
104+
value={email}
105+
onChangeText={setEmail}
106+
style={styles.input}
107+
/>
108+
109+
<TextInput
110+
placeholder="Enter password"
111+
textContentType="password"
112+
secureTextEntry
113+
value={password}
114+
onChangeText={setPassword}
115+
style={styles.input}
116+
/>
117+
118+
<BorderlessButton onPress={handleSubmit} style={styles.button}>
119+
<Text style={{ textAlign: 'center' }}>Submit</Text>
120+
</BorderlessButton>
121+
</View>
122+
</Screen>
123+
);
124+
}
125+
126+
function Screen({ children, background = 'transparent' }: any) {
127+
return (
128+
<View style={{ flex: 1, backgroundColor: background }}>{children}</View>
129+
);
130+
}
131+
132+
const styles = StyleSheet.create({
133+
title: {
134+
flex: 1,
135+
justifyContent: 'center',
136+
alignItems: 'center',
137+
fontSize: 18,
138+
fontWeight: 'bold',
139+
alignSelf: 'center',
140+
textAlign: 'center',
141+
},
142+
143+
button: {
144+
borderWidth: 1,
145+
borderRadius: 4,
146+
padding: 10,
147+
marginVertical: 10,
148+
},
149+
150+
input: {
151+
borderWidth: 1,
152+
marginVertical: 10,
153+
fontSize: 16,
154+
padding: 5,
155+
height: 40,
156+
borderRadius: 4,
157+
width: '100%',
158+
},
159+
});
160+
161+
export { Entry };

0 commit comments

Comments
 (0)