-
Notifications
You must be signed in to change notification settings - Fork 2
/
App.js
125 lines (114 loc) · 2.7 KB
/
App.js
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
import React, { useState } from "react";
import {
SafeAreaView,
View,
Modal,
StyleSheet,
TextInput,
TouchableOpacity,
Text,
Alert,
Platform
} from "react-native";
import * as LocalAuthentication from "expo-local-authentication";
export default function App() {
const [isModalVisible, setIsModalVisible] = useState(true);
async function authenticate() {
const hasPassword = await LocalAuthentication.isEnrolledAsync();
if (!hasPassword) return;
const { success, error } = await LocalAuthentication.authenticateAsync();
if (success) {
Alert.alert("Autenticação realizada com sucesso");
} else {
Alert.alert("A autenticação falhou. Por favor, digite sua senha!");
}
setIsModalVisible(false);
}
Platform.OS === "ios" && authenticate();
return (
<SafeAreaView style={styles.container}>
<TextInput
style={styles.input}
placeholder="Email"
placeholderTextColor="#444"
/>
<TextInput
style={styles.input}
placeholder="Senha"
placeholderTextColor="#444"
/>
<TouchableOpacity style={styles.button}>
<Text>Entrar</Text>
</TouchableOpacity>
{Platform.OS === "android" && (
<Modal
animationType="slide"
transparent={true}
visible={isModalVisible}
onShow={authenticate}
>
<View style={styles.modal}>
<Text style={styles.authText}>
Autentique-se utilizando sua digital
</Text>
<TouchableOpacity
onPress={() => {
LocalAuthentication.cancelAuthenticate();
setIsModalVisible(false);
}}
>
<Text style={styles.cancelText}>Cancelar</Text>
</TouchableOpacity>
</View>
</Modal>
)}
</SafeAreaView>
);
}
const styles = StyleSheet.create({
container: {
backgroundColor: "#19181f",
flex: 1,
justifyContent: "center",
alignItems: "center"
},
input: {
width: 200,
height: 45,
borderWidth: 2,
borderColor: "#7159c1",
borderRadius: 5,
marginBottom: 10,
padding: 10
},
button: {
width: 200,
height: 45,
borderWidth: 2,
borderColor: "#7159c1",
backgroundColor: "#7159c1",
borderRadius: 5,
marginBottom: 10,
padding: 10,
justifyContent: "center",
alignItems: "center"
},
modal: {
backgroundColor: "#333",
position: "absolute",
left: 0,
right: 0,
bottom: 0,
justifyContent: "center",
alignItems: "center",
height: "40%"
},
cancelText: {
color: "red",
fontSize: 16
},
authText: {
color: "white",
fontSize: 16
}
});