Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import React, { Component } from 'react';
- import {AsyncStorage, StatusBar, ToastAndroid, Keyboard} from 'react-native';
- import { Container, Header, Content, Form, Item, Input, Label,Button, Text, Title, Left, Body, Right, Icon,
- Card, CardItem,} from 'native-base';
- import { NavigationActions } from "react-navigation";
- import Storage from 'react-native-storage';
- import axios from 'axios';
- import styles from './styles';
- // import Storage from 'react-native-storage';
- this.props.navigation.dispatch(NavigationActions.reset({
- index: 0,
- actions: [
- NavigationActions.navigate({ routeName: 'HomeScreen' })
- ]
- }))
- export default class Login extends Component {
- constructor(props) {
- super(props);
- this.state = {
- email : '',
- password : '',
- isLoading : true,
- token: '',
- isLoggedIn: false
- };
- this.LoginUser = this.LoginUser.bind(this);
- }
- //for login\\\
- LoginUser = () =>{
- // this.setState({
- // isLoading: true
- // })
- // console.log(id);
- if (this.state.email == "") {
- ToastAndroid.show('nama Tidak Boleh Kosong', ToastAndroid.SHORT)
- } else if (this.state.password == "") {
- ToastAndroid.show('Password Tidak Boleh Kosong', ToastAndroid.SHORT)
- } else {
- this.setState({
- isLoading: false
- })
- axios({
- method: 'POST',
- url: 'api',
- data: {
- email : this.state.email,
- password : this.state.password
- },
- })
- .then(response => {
- if (response == 'Try Again') {
- ToastAndroid.show('Try Again, the input is empty', ToastAndroid.SHORT)
- } else {
- ToastAndroid.show('sukses', ToastAndroid.SHORT)
- this.props.navigation.dispatch(resetAction)
- // this.props.navigation.dispatch(goHome)
- // console.log(navigateAction)
- }
- })
- .catch((error) => {
- console.error(error);
- });
- Keyboard.dismiss()
- }
- }
- // console.log(response.data);
- // alert('gagal')
- // this.storeToAsyncStorage(response.data);
- render() {
- // const { navigate } = this.props.navigation;
- return (
- <Container>
- <Header style={styles.header}>
- <StatusBar
- backgroundColor="#e60000"
- barStyle="light-content"
- />
- <Left />
- {/*<Button transparent>
- <Icon name='menu' />
- </Button>
- </Left>*/}
- <Body>
- <Title>Header</Title>
- </Body>
- <Right />
- </Header>
- <Content style={styles.content} >
- <Content style={styles.login}>
- <Form>
- <Item floatingLabel last style={styles.Lname}>
- <Label style={styles.name}>User name</Label>
- <Input
- onChangeText= {email => this.setState({email})}
- returnKeyType="next"
- />
- </Item>
- <Item floatingLabel last style={styles.Lpassword}>
- <Label style={styles.password}>Password</Label>
- <Input
- onChangeText= {password => this.setState({password})}
- autoCorrect={false}
- returnKeyType="go"
- // ref={(input)=> this.passwordInput = input}
- secureTextEntry
- />
- </Item>
- </Form>
- <Button block style={styles.button}
- onPress={this.LoginUser}
- >
- <Text>Login</Text>
- </Button>
- {/*
- <Button style={styles.Ltext}>
- <Text style={{color: '#000000'}} >atau</Text>
- </Button>
- <Button iconLeft block style={styles.fb}>
- <Icon name='logo-facebook' />
- <Text>Login With Facebook</Text>
- </Button>
- <Button iconLeft block transparent danger style={styles.google}>
- <Icon name='logo-googleplus' />
- <Text>Login With Google</Text>
- </Button>
- */}
- </Content>
- </Content>
- </Container>
- );
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement