Skip to content

Instantly share code, notes, and snippets.

@TiagoSSGaspar
Last active August 21, 2021 13:57
Show Gist options
  • Select an option

  • Save TiagoSSGaspar/8e929fd3b596a13811a5eba35db2e040 to your computer and use it in GitHub Desktop.

Select an option

Save TiagoSSGaspar/8e929fd3b596a13811a5eba35db2e040 to your computer and use it in GitHub Desktop.
Biscoito da sorte react-native
import React, {Component} from 'react';
import {Image, View, Text, StyleSheet,TouchableOpacity} from "react-native";
export default class App extends Component {
constructor(props) {
super(props);
this.state = {
textoFrase: '',
img: require('./src/biscoito.png')
};
this.toraBiscoito = this.toraBiscoito.bind(this);
this.frases = [
'Siga os bons e aprenda com eles.',
'O bom-senso vale mais do que muito conhecimento.',
'O riso é a menor distância entre duas pessoas.',
'Deixe de lado as preocupações e seja feliz.',
'Realize o óbvio, pense no improvável e conquiste o impossível.',
'Acredite em milagres, mas não dependa deles.',
'A maior barreira para o sucesso é o medo do fracasso.'
];
}
toraBiscoito(){
let numeroAleatorio = Math.floor(Math.random() * this.frases.length);
this.setState({
textoFrase: this.frases[numeroAleatorio],
img: require('./src/biscoitoAberto.png')
})
}
render() {
return (
<View style={style.container}>
<Image source={this.state.img} style={style.imgStyle} />
<Text style={style.textoFrase}>"{this.state.textoFrase}"</Text>
<TouchableOpacity style={style.btn} onPress={this.toraBiscoito}>
<View style={style.btnArea}>
<Text style={style.btnTexto}>Tora o biscoito</Text>
</View>
</TouchableOpacity>
</View>
);
}
}
const style = StyleSheet.create({
container: {
flex: 1,
backgroundColor:'gray',
alignItems: 'center',
justifyContent: 'center'
},
textoFrase: {
textAlign: 'center',
fontSize: 25,
margin: 35,
color: '#dd7b22',
fontStyle: 'italic'
},
imgStyle:{
width: 350,
height: 350
},
btn:{
width: 230,
height: 50,
borderWidth: 2,
borderColor: '#dd7b22',
borderRadius: 25
},
btnArea:{
flex:1,
flexDirection: 'row',
justifyContent: 'center',
alignItems: 'center'
},
btnTexto:{
fontSize: 20,
fontWeight: 'bold',
color: '#dd7b22'
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment