index.js 3.8 KB

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