-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathApp.tsx
196 lines (177 loc) · 5.08 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
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
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
import React, { useEffect, useState } from 'react'
import { View, StatusBar, SafeAreaView, StyleSheet, Image, TouchableOpacity } from 'react-native'
import { Toast, Root, Text } from 'native-base'
import * as Font from 'expo-font'
import Slider from "@react-native-community/slider"
import Checkbox from '@react-native-community/checkbox'
import Clipboard from 'expo-clipboard';
import { Ionicons } from '@expo/vector-icons'
export default function App() {
const [appReady, setAppReady] = useState(false)
const [password, setPassword] = useState('')
const [size, setSize] = useState(10)
const [specialChars, setSpecialChars] = useState(false)
const charsetMap = 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890!@#$%*()-={}[]' // -14
useEffect(() => {
async function StartApplication() {
await loadFonts()
}
async function loadFonts() {
await Font.loadAsync({
'Roboto': require('native-base/Fonts/Roboto.ttf'),
'Roboto_medium': require('native-base/Fonts/Roboto_medium.ttf'),
...Ionicons.font,
})
setAppReady(true)
}
StartApplication()
}, [])
function generatePassword() {
let passwd = ''
let charmapSize = specialChars ? charsetMap.length : charsetMap.length - 14
for (let i = 0; i < size; i++) {
passwd += charsetMap.charAt(Math.floor(Math.random() * charmapSize))
}
setPassword(passwd)
}
function copyToClipboard() {
Clipboard.setString(password)
Toast.show({
text: 'Senha copiada',
buttonText: "Done",
type: "success",
duration: 1000
})
}
return (
<>
{
appReady ? (
<Root>
<StatusBar
backgroundColor="#ffbb00"
barStyle="light-content"
/>
<SafeAreaView style={appStyles.container}>
<Image style={appStyles.image} source={require('./src/assets/lock-icon.png')} />
<Text style={appStyles.charLabel}>{size} Caracteres</Text>
<View style={appStyles.sliderContainer}>
<Slider
style={appStyles.slider}
minimumValue={5}
maximumValue={15}
minimumTrackTintColor="#f00"
maximumTrackTintColor="#080"
value={size}
step={1}
onValueChange={(value) => setSize(Number(value.toFixed(0)))}
/>
</View>
<View style={appStyles.checkboxContainer} onTouchEndCapture={() => setSpecialChars(!specialChars)}>
<Checkbox
value={specialChars}
tintColors={{ true: '#ffa600', false: '#ffa600' }}
/>
<Text style={appStyles.checkboxLabel}>Usar caracteres especiais</Text>
</View>
<TouchableOpacity
style={{ ...appStyles.sliderContainer, backgroundColor: "#ffbb00" }}
onPress={generatePassword}
>
<Text style={appStyles.buttonText}>Gerar senha</Text>
</TouchableOpacity>
{
password !== '' &&
<View style={{ ...appStyles.spaceContainer, backgroundColor: "#f0f0f0" }}>
<Text style={appStyles.generatedPassword}
onLongPress={copyToClipboard}
>
{password}
</Text>
<Ionicons
name="clipboard"
size={24}
color="#fff"
style={appStyles.copyButton}
onPress={copyToClipboard}
/>
</View>
}
</SafeAreaView>
</Root>
)
: <Text>Loading</Text>
}
</>
)
}
const appStyles = StyleSheet.create({
container: {
flex: 1,
justifyContent: "center",
alignItems: "center",
padding: '10%'
},
image: {
width: 140,
height: 140,
},
charLabel: {
marginTop: 40,
fontSize: 30,
fontWeight: 'bold',
},
sliderContainer: {
marginTop: 20,
width: '100%',
justifyContent: 'center',
alignItems: 'center',
backgroundColor: '#f0f0f0',
maxHeight: 50,
flexDirection: 'row',
borderRadius: 10,
flex: 1
},
slider: {
width: '100%',
},
spaceContainer: {
marginTop: 50,
height: 55,
width: '100%',
justifyContent: 'center',
alignItems: 'center',
borderRadius: 10,
flexDirection: 'row',
},
buttonText: {
color: "#fff",
fontSize: 20,
},
generatedPassword: {
paddingLeft: 15,
textAlign: 'center',
fontWeight: "bold",
fontSize: 20,
flex: 1
},
copyButton: {
flex: .25,
backgroundColor: "#ffbb00",
color: "#fff",
height: "100%",
textAlignVertical: 'center',
textAlign: 'center',
borderTopRightRadius: 10,
borderBottomRightRadius: 10,
},
checkboxContainer: {
padding: 5,
flexDirection: 'row',
justifyContent: 'center',
alignItems: 'center',
},
checkboxLabel: {
color: 'rgba(0, 0, 0, .5)',
},
})