Advertisement
Guest User

Untitled

a guest
Jun 16th, 2019
124
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.50 KB | None | 0 0
  1. constructor(props){
  2. super(props)
  3. this.state = {
  4. personName : '',
  5. }
  6. }
  7.  
  8. goToHomePage = async() => {
  9. if(this.state.personName == ''){
  10. alert('Informe seu nome')
  11. }else{
  12. try {
  13. await AsyncStorage.setItem('name', this.state.personName)
  14. Actions.home()
  15. } catch(e){
  16. return e
  17. }
  18. }
  19. }
  20.  
  21.  
  22.  
  23. render(){
  24. return(
  25. <View style={styles.container}>
  26. <Text style={styles.text}>
  27. Obrigado por nos ajudar no combate a dengue !
  28. </Text>
  29.  
  30. <TextInput style={styles.input}
  31. placeholder="Informe seu nome"
  32. placeholderTextColor="#fff"
  33. onChangeText={(personName) => this.setState({personName})}
  34. value = {this.state.personName}
  35. />
  36.  
  37. <TouchableOpacity style={styles.button}
  38. onPress = {this.goToHomePage}
  39. >
  40.  
  41. <Text style={styles.buttonText}>
  42. Entrar
  43. </Text>
  44.  
  45. </TouchableOpacity>
  46.  
  47. </View>
  48.  
  49. )
  50. }
  51.  
  52. getData = async() => {
  53. try{
  54. const username = await AsyncStorage.getItem('name')
  55. if(username !== null){
  56. return username
  57. }
  58. }catch(e){
  59. return e
  60. }
  61.  
  62. }
  63.  
  64. render(){
  65. return(
  66.  
  67. <View style={styles.container}>
  68. <Text style={styles.text}>
  69. {this.getData}
  70. </Text>
  71. </View>
  72. )
  73. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement