Advertisement
Guest User

Untitled

a guest
Mar 4th, 2017
129
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. import React, { Component } from 'react';
  2.  
  3. import {
  4.     View,
  5.     StyleSheet,
  6.     Text,
  7.     TouchableHighlight,
  8.     Image,
  9.     TextInput,
  10.     ActivityIndicator,
  11.     ToastAndroid
  12. } from 'react-native';
  13.  
  14. import authService from'./AuthService/AuthService';
  15.  
  16.  
  17. export default class Login extends Component {
  18.     constructor(props){
  19.         super(props);
  20.         this.state={
  21.             username:undefined,
  22.             password:undefined,
  23.             animation:false,
  24.             badCredentials:false,
  25.             success:false
  26.         };
  27. }
  28.    
  29.     render() {
  30.          var errorCtrl=<View/>
  31.          if(!this.state.success && this.state.badCredentials){
  32.                 errorCtrl=<Text style={styles.error}>that username and password combination did not work</Text>
  33.          }
  34.         return (
  35.             <View style={styles.container}>
  36.                 <Image source={require('./img/Octocat.png')} style={styles.logo} />
  37.                 <Text style={styles.heading}>Github browser</Text>
  38.                 <TextInput style={styles.input}
  39.                     placeholder={"Github username"}
  40.                     onChangeText={(text) => this.setState({username:text})}
  41.                    
  42.                     />
  43.                 <TextInput style={styles.input}
  44.                     placeholder={"Github user password"}
  45.                     secureTextEntry={true}
  46.                     onChangeText={(text)=>this.setState({password:text})}
  47.                    
  48.                     />
  49.                 <TouchableHighlight
  50.                     style={styles.button}
  51.                     onPress={this.onLoginPressed.bind(this)}
  52.                 >
  53.                 <Text style={styles.buttonText}>Log in</Text>
  54.                 </TouchableHighlight>    
  55.                     {errorCtrl}
  56.                 <ActivityIndicator
  57.                     animating={this.state.animation}
  58.                     size="large"
  59.                 />
  60.             </View>
  61.         )
  62.     }
  63.  
  64.     onLoginPressed(){
  65.         this.setState({animation:true});
  66.         console.log('onLoginPressed', this);
  67.         authService.login({
  68.             username : this.state.username,
  69.             password: this.state.password
  70.         },(results)=>{
  71.             console.log('results', this);
  72.             this.setState(results);
  73.             if(this.state.success && this.props.onLogin){
  74.                 this.props.onLogin();
  75.             }
  76.         });
  77.      }
  78. }
  79. const styles = StyleSheet.create({
  80.     container: {
  81.         flex: 1,
  82.         backgroundColor: '#F5FCFF',
  83.         paddingTop: 40,
  84.         alignItems: 'center',
  85.         padding: 10,
  86.        
  87.     },
  88.     logo: {
  89.         width: 88,
  90.         height: 77
  91.     },
  92.     heading: {
  93.         fontSize: 30,
  94.         marginTop: 10
  95.     },
  96.     input: {
  97.         height: 50,
  98.         marginTop: 10,
  99.         padding: 4,
  100.         fontSize: 18,
  101.         borderWidth: 1,
  102.         alignSelf: 'stretch',
  103.         borderColor: '#48bbec'
  104.     },
  105.  
  106.     button:{
  107.         height:50,
  108.         backgroundColor:"#48BBEC",
  109.         alignSelf:'stretch',
  110.         marginTop:10,
  111.         justifyContent:'center',
  112.  
  113.     },
  114.     buttonText:{
  115.         fontSize:22,
  116.         color:"#fff",
  117.         alignSelf:'center'
  118.     },
  119.    error:{
  120.        color:'red',
  121.        paddingTop: 10
  122.    }
  123.  
  124. })
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement