Login.js 4.01 KB
'use strict';

import React from 'react-native';
import Button from 'apsl-react-native-button';

let {
    StyleSheet,
    Component,
    View,
    Image,
    Text,
    Dimensions,
    TextInput,
    TouchableWithoutFeedback
} = React;

export default class Login extends Component {

    constructor(props) {
        super(props);
    }

    static propTypes = {
        account: React.PropTypes.string,
        pwd: React.PropTypes.string,
        isFetching:React.PropTypes.bool,
        isDisplayPwd:React.PropTypes.bool,
        onLoginPress: React.PropTypes.func,
        onDeleteUserPress: React.PropTypes.func,
        onShowPwdPress: React.PropTypes.func,
        onAccountChange:React.PropTypes.func,
        onPwdChange:React.PropTypes.func,
    };


    renderUserText() {
              return (
                  <View style={styles.textContainer}>
                    <TextInput
                      style={styles.username}
                      placeholder='账号'
                      underlineColorAndroid='transparent'
                      onChangeText={this.props.onAccountChange}
                      value={this.props.account}
                    />
                    <TouchableWithoutFeedback
                      onPress={this.props.onDeleteUserPress}>
                      <Image
                        style={styles.buttonDelete}
                        source={require('../images/delete.png')
                        }
                        />
                     </TouchableWithoutFeedback>
                  </View>
                );
  }
  renderPwdText() {
              return (
                    <View style={styles.textContainer}>
                      <TextInput
                        style={styles.pwd}
                        secureTextEntry={this.props.isDisplayPwd?false:true}
                        placeholder={'密码'}
                        underlineColorAndroid='transparent'
                        onChangeText={this.props.onPwdChange}
                        value={this.props.pwd}
                        />
                      <TouchableWithoutFeedback
                        onPress={this.props.onShowPwdPress}>
                          <Image
                            style={styles.buttonDelete}
                            source={require('../images/eyes@2x.png')}
                          />
                      </TouchableWithoutFeedback>
                    </View>
              );  
  }
	render() {

        return (
          
            <Image style={styles.container} source={require('../images/login@2x.png')} resizeMode={'cover'} >
              <Image
                style={styles.logo}
                source={require('../images/logo@2x.png')}
                />
              {this.renderUserText()}
              {this.renderPwdText()}
              <Button style={styles.button}
                  textStyle={styles.buttonText}
                  onPress={this.props.onLoginPress}>
                   登录
                 </Button>
            </Image>
        );
    }
}

let {height, width} = Dimensions.get('window');
let textPaddingTop = height * 7 / 10;
let buttonMargin = (width - 320) / 2;
let inputWidth = width-40;
var styles = StyleSheet.create({
  container:{
    flex: 1,
    flexDirection: 'column',
    alignItems: 'center',
    justifyContent: 'center',
    width: width,
    height: height,
  },
  textContainer:{
    flexDirection: 'row',
    alignItems: 'center',
    width:inputWidth,
    height:40,
    justifyContent: 'center',
    borderRadius:5,
    backgroundColor: 'gray',
    marginBottom: 10,
  },
  logo: {
    width:256,
    height:40,
    marginBottom: 40,
  },
  username: {
    flex: 1,
    height:40,
    paddingLeft:10,


  },
  pwd: {
    flex: 1,
    paddingLeft:10,

  },
  button: {
      marginLeft: 20,
      marginRight: 20,
      backgroundColor: '#ffffff',
      opacity:0.5,
      borderWidth:0,
      borderRadius:5,
  },
  buttonText: {
      color: 'black',
      fontSize: 18,
  },
  buttonDelete: {
    width:20,
    height:20,
    marginRight:10,
  },
});