-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathApp.js
76 lines (69 loc) · 1.73 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
import React, { useState } from 'react';
import { View, Text, Image, StyleSheet, TouchableOpacity, Alert } from 'react-native';
function App(){
const [img, setImg] = useState(require('./src/biscoito.png'));
const [textSentence, setTextSentence] = useState('');
const [isVisible, setIsVisible] = useState(true);
let sentences = require('./src/sentences.json').sentences;
function breakCookie(){
let randomNumber = Math.floor(Math.random() * sentences.length);
setTextSentence("\"" + sentences[randomNumber] + "\"");
setImg(require('./src/biscoitoAberto.png'));
setIsVisible(false);
setTimeout(() => {
setImg(require('./src/biscoito.png'));
setTextSentence('');
setIsVisible(true);
}, 2000);
}
return (
<View style={styles.container}>
<Image
source={img}
style={styles.img}
/>
<Text style={styles.sentenceText}>{ textSentence }</Text>
<TouchableOpacity style={styles.button} onPress={breakCookie}>
<View style={styles.buttonArea}>
<Text style={styles.buttonText}>Open Cookie</Text>
</View>
</TouchableOpacity>
</View>
);
}
const styles = StyleSheet.create({
container: {
flex: 1,
alignItems: 'center',
justifyContent: 'center',
},
img: {
width: 230,
height: 230
},
sentenceText:{
fontSize: 20,
color: '#dd7b22',
margin: 30,
fontStyle: 'italic',
textAlign: 'center'
},
button: {
width: 230,
height: 50,
borderColor: '#dd7b22',
borderWidth: 2,
borderRadius: 10
},
buttonArea: {
flex: 1,
justifyContent: 'center',
alignItems: 'center',
},
buttonText: {
fontWeight: 'bold',
fontSize: 18,
color: '#dd7b22'
}
})
export default App;