Advertisement
Guest User

Untitled

a guest
Apr 19th, 2019
95
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.89 KB | None | 0 0
  1. import React, { Component } from 'react';
  2. import { View, Text, StyleSheet, StatusBar, Image, AsyncStorage, ActivityIndicator } from 'react-native';
  3. import { Form, Item, Input, Label, Button } from 'native-base';
  4. import Axios from 'axios';
  5. import CONFIG from '../config/config';
  6.  
  7. export default class LoginScreen extends Component {
  8. constructor(props) {
  9. super(props)
  10. this.state = { _email: '', _pass: '' }
  11. }
  12.  
  13. static navigationOptions = {
  14. drawerLabel: () => null,
  15. drawerLockMode: 'locked-open'
  16. }
  17.  
  18. Logar = async () => {
  19. this.setState({ isLoading: true })
  20.  
  21. Axios.post(CONFIG + "login", { email: 'admin@turbbo.com.br', password: '123456789' }).then(response => {
  22. console.log("TOKEN >> " + JSON.stringify(response.data.access_token));
  23. AsyncStorage.setItem('Logado', response.data.access_token)
  24. this.props.navigation.navigate('Home');
  25. }).catch(function (error) {
  26. console.log(error);
  27. });
  28. }
  29.  
  30. render() {
  31. return (
  32. <View style={styles.container}>
  33. {
  34. this.state.isLoading &&
  35. <View style={{ flex: 2, alignContent: "center", justifyContent: "center", position: "absolute", top: "30%" }}>
  36. <ActivityIndicator size="large" color="#0000ff" />
  37. </View>
  38. }
  39. <StatusBar hidden />
  40. <View style={styles.headerText}>
  41. <Image source={require('../../assets/logo.png')} style={{ width: 199, height: 70, marginTop: 10 }} />
  42. </View>
  43. <View style={styles.formLogin}>
  44. <Form>
  45. <Item stackedLabel>
  46. <Label>Email</Label>
  47. <Input onChangeText={(email) => this.setState({ _email: email })} />
  48. </Item>
  49. <Item stackedLabel>
  50. <Label>Pass</Label>
  51. <Input onChangeText={(pass) => this.setState({ _pass: pass })} secureTextEntry={true} />
  52. </Item>
  53. <Button block style={styles.buttonLogin} onPress={() => this.Logar()} disabled={this.state.isLoading} isLoading={this.state.isLoading} activeOpacity={0.8} ><Text>ACESSAR</Text></Button>
  54. <Button block light style={{ marginTop: 5, alignContent: 'center', textAlign: 'center' }} onPress={() => this.props.navigation.navigate('Cadastro')}><Text>Criar Conta</Text></Button>
  55. </Form>
  56. </View>
  57. </View>
  58. )
  59. }
  60. }
  61.  
  62. const styles = StyleSheet.create({
  63. container: { flex: 1 },
  64. headerText: { flex: 2, alignItems: 'center', justifyContent: 'center' },
  65. formLogin: { flex: 3 },
  66. buttonLogin: { marginTop: 50 }
  67. });
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement