index.js 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122
  1. import React,{Component} from 'react';
  2. import PropTypes from 'prop-types';
  3. import {StyleSheet, View,StatusBar,Image ,Text,Dimensions,AsyncStorage} from 'react-native';
  4. import { KeyboardAwareScrollView } from 'react-native-keyboard-aware-scroll-view'
  5. import {Button} from 'antd-mobile-rn';
  6. import commonStyle from '../../styles/styles.js';
  7. import LoginInput from '../../components/LoginInput';
  8. import Leancloud from '../../leancloud'
  9. const {width,height} = Dimensions.get('window');
  10. class LoginScreen extends Component{
  11. static navigationOptions = {title: '登录',header:null}
  12. async componentWillMount(){
  13. let user = JSON.parse(await AsyncStorage.getItem('USERINFO'))
  14. if(user) {
  15. this.setState({
  16. telphone:user.telphone,
  17. password:user.password
  18. },()=>{
  19. this.submit()
  20. })
  21. }
  22. }
  23. constructor(props){
  24. super(props)
  25. this.state={
  26. telphone:"",
  27. password:""
  28. }
  29. }
  30. submit(){
  31. const {navigation} = this.props
  32. const {telphone,password} = this.state
  33. Leancloud.login(telphone,password,navigation)
  34. }
  35. render(){
  36. const {telphone,password} = this.state
  37. return (
  38. <View style={[commonStyle.page,{backgroundColor:'#fff'}]}>
  39. <KeyboardAwareScrollView
  40. extraScrollHeight={50}
  41. >
  42. <StatusBar
  43. animated={true} //指定状态栏的变化是否应以动画形式呈现。目前支持这几种样式:backgroundColor, barStyle和hidden
  44. hidden={true} //是否隐藏状态栏。
  45. translucent={false}//指定状态栏是否透明。设置为true时,应用会在状态栏之下绘制(即所谓“沉浸式”——被状态栏遮住一部分)。常和带有半透明背景色的状态栏搭配使用。
  46. barStyle={'light-content'} // enum('default', 'light-content', 'dark-content')
  47. >
  48. </StatusBar>
  49. <View style={styles.bgView}>
  50. <Image source={require('../../../assets/2x/Login/bg.png')} style={styles.bgViewImage}></Image>
  51. </View>
  52. <View style={[styles.form,{}]}>
  53. <Text style={{fontSize:17,color:'#b3b3b3',marginTop:10}}>登录</Text>
  54. <Image source={require('../../../assets/2x/Login/line.png')} style={{height:2,width:60,marginTop:10}}></Image>
  55. <LoginInput type='text' style={{marginTop:45}}
  56. onChange={(telphone)=>{
  57. this.setState({
  58. telphone
  59. })
  60. }}
  61. text={telphone}
  62. ></LoginInput>
  63. <LoginInput type='password' placeholder='请输入密码' style={{marginTop:30}}
  64. onChange={(password)=>{
  65. this.setState({
  66. password
  67. })
  68. }}
  69. text={password}
  70. ></LoginInput>
  71. <Button type="primary" onClick={
  72. ()=>this.submit()
  73. }
  74. style={styles.btn}
  75. >
  76. <Text style={{fontSize:14}}>立即登录</Text>
  77. </Button>
  78. </View>
  79. </KeyboardAwareScrollView>
  80. </View>
  81. )
  82. }
  83. }
  84. const styles = StyleSheet.create({
  85. bgView:{
  86. width,
  87. flex:1,
  88. height:667,
  89. },
  90. bgViewImage:{
  91. width,
  92. height:667,
  93. },
  94. form:{
  95. width:325,
  96. height:330,
  97. left:24-(375-width)/2,
  98. top:217,
  99. position:'absolute',
  100. padding:26,
  101. alignItems:'center'
  102. },
  103. btn:{
  104. width:280,
  105. height:40,
  106. borderRadius:20,
  107. marginTop:40
  108. }
  109. });
  110. export default (LoginScreen);