index.js 3.6 KB

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