-
Notifications
You must be signed in to change notification settings - Fork 1
/
App.tsx
94 lines (91 loc) · 2.09 KB
/
App.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
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
import { useState } from "react";
import {
StyleSheet,
Text,
TextInput,
TouchableOpacity,
View,
} from "react-native";
export default function App() {
const [username, setUsername] = useState<string>("");
const [password, setPassword] = useState<string>("");
const [valid, setValid] = useState(false);
return (
<View style={styles.container}>
<View style={styles.inputGroup}>
<Text style={styles.label}>Username</Text>
<TextInput
style={styles.input}
placeholder="Username"
onChange={(e) => setUsername(e.nativeEvent.text)}
testID="usernameInput"
/>
</View>
<View style={styles.inputGroup}>
<Text style={styles.label}>Password</Text>
<TextInput
style={styles.input}
placeholder="Password"
secureTextEntry
onChange={(e) => setPassword(e.nativeEvent.text)}
testID="passwordInput"
/>
</View>
<TouchableOpacity
style={styles.button}
onPress={() => {
if (username.length > 0 && password.length > 0) {
setValid(true);
} else {
setValid(false);
}
}}
testID="signInButton"
>
<Text style={styles.buttonText}>Sign in</Text>
</TouchableOpacity>
{valid ? <Text style={styles.successText}>Sign in successfully</Text> : null}
</View>
);
}
const styles = StyleSheet.create({
container: {
flex: 1,
padding: 24,
backgroundColor: "#fff",
justifyContent: "center",
},
inputGroup: {
marginBottom: 16,
},
label: {
fontSize: 12,
fontWeight: "bold",
marginBottom: 6,
},
input: {
borderRadius: 8,
borderWidth: 1,
borderColor: "gray",
padding: 12,
width: "100%",
fontSize: 18,
},
button: {
borderRadius: 8,
padding: 12,
backgroundColor: "black",
alignItems: "center",
marginBottom: 8,
},
buttonText: {
fontSize: 16,
fontWeight: "bold",
color: "white",
},
successText: {
fontSize: 16,
color: "green",
alignSelf: 'center',
},
});