-
Notifications
You must be signed in to change notification settings - Fork 0
/
App.js
104 lines (89 loc) · 2.29 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
import React, { useState } from 'react';
import { View, Text, StyleSheet, Image, TouchableOpacity } from 'react-native';
import Slider from '@react-native-community/slider';
import Clipboard from 'expo-clipboard';
let charset = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789";
export default function App(){
const [password, setPassword] = useState('');
const [size, setSize] = useState(5);
function generatePass(){
let pass = "";
for(let i = 0, n = charset.length; i < size; i++){
pass += charset.charAt(Math.floor(Math.random() * n));
}
setPassword(pass);
}
function copyPass(){
Clipboard.setString(password);
alert('Senha copiada com sucesso!');
}
return(
<View style={styles.container}>
<Image
source={require('./src/assets/logo.png')}
style={styles.logo}
/>
<Text style={styles.title}>{ size } Caracteres</Text>
<View style={styles.area}>
<Slider
style={{height: 50}}
minimumValue={5}
maximumValue={15}
minimumTrackTintColor ="#ff0000"
maximumTrackTintColor = "#000000"
value={size}
onValueChange={(value) => setSize(value.toFixed(0))}
/>
</View>
<TouchableOpacity style={styles.button} onPress={generatePass}>
<Text style={styles.buttonText}>Gerar senha</Text>
</TouchableOpacity>
{password !== "" && (
<View style={styles.area}>
<Text style={styles.password} onLongPress={copyPass}> { password } </Text>
</View>
)}
</View>
)
}
const styles = StyleSheet.create({
container:{
flex: 1,
alignItems: "center",
justifyContent: "center",
backgroundColor: "#f3f3ff",
},
logo:{
marginBottom: 60,
},
title:{
fontSize: 30,
fontWeight: "bold",
},
area:{
marginTop: 15,
marginBottom: 15,
backgroundColor: "#ffffff",
width: "90%",
borderRadius: 7,
},
button:{
backgroundColor: "#ffa200",
width: "80%",
height: 50,
borderRadius: 7,
marginBottom: 25,
justifyContent: "center",
alignItems: "center",
},
buttonText:{
fontSize: 20,
color: "#ffffff",
fontWeight: "bold",
},
password:{
padding: 10,
textAlign:"center",
fontSize: 20,
}
})