Advertisement
Guest User

Untitled

a guest
May 25th, 2019
76
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.45 KB | None | 0 0
  1. import React, { Component } from 'react';
  2. import {
  3. StyleSheet,
  4. Text,
  5. View,
  6. TextInput,
  7. TouchableHighlight,
  8. } from 'react-native';
  9.  
  10. export default class LoginView extends Component {
  11.  
  12. constructor(props) {
  13. super(props);
  14. this.state = {
  15. email:"",
  16. password:"",
  17. }
  18. }
  19. validateEmail = (email) => {
  20. let checkEmail = /^(([^<>()\[\]\\.,;:\s@"]+(\.[^<>()\[\]\\.,;:\s@"]+)*)|(".+"))@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}])|(([a-zA-Z\-0-9]+\.)+[a-zA-Z]{2,}))$/;
  21. return checkEmail.test(email);
  22. };
  23.  
  24. submitForm = () => {
  25. const { email, password } = this.state;
  26. if(email.trim() === '' || password.trim() === '' || !this.validateEmail(email)){
  27. console.log('error')
  28. return
  29. }
  30.  
  31. console.log('cool its ok')
  32. //now you can send it to your server
  33.  
  34. }
  35.  
  36. render() {
  37. return (
  38. <View style={styles.container}>
  39. <View style={styles.inputContainer}>
  40. <TextInput style={styles.inputs}
  41. placeholder="Email"
  42. keyboardType="email-address"
  43. underlineColorAndroid='transparent'
  44. onChangeText={(email) => this.setState({email})}/>
  45. </View>
  46.  
  47. <View style={styles.inputContainer}>
  48. <TextInput style={styles.inputs}
  49. placeholder="Password"
  50. secureTextEntry={true}
  51. underlineColorAndroid='transparent'
  52. onChangeText={(password) => this.setState({password})}/>
  53. </View>
  54.  
  55. <TouchableHighlight style={[styles.buttonContainer, styles.loginButton]} onPress={this.submitForm}>
  56. <Text style={styles.loginText}>Login</Text>
  57. </TouchableHighlight>
  58.  
  59. </View>
  60. );
  61. }
  62. }
  63.  
  64. const styles = StyleSheet.create({
  65. container: {
  66. flex: 1,
  67. justifyContent: 'center',
  68. alignItems: 'center',
  69. backgroundColor: '#DCDCDC',
  70. },
  71. inputContainer: {
  72. borderBottomColor: '#F5FCFF',
  73. backgroundColor: '#FFFFFF',
  74. borderRadius:30,
  75. borderBottomWidth: 1,
  76. width:250,
  77. height:45,
  78. marginBottom:20,
  79. flexDirection: 'row',
  80. alignItems:'center'
  81. },
  82. inputs:{
  83. height:45,
  84. marginLeft:16,
  85. borderBottomColor: '#FFFFFF',
  86. flex:1,
  87. },
  88. buttonContainer: {
  89. height:45,
  90. flexDirection: 'row',
  91. justifyContent: 'center',
  92. alignItems: 'center',
  93. marginBottom:20,
  94. width:250,
  95. borderRadius:30,
  96. },
  97. loginButton: {
  98. backgroundColor: "#00b5ec",
  99. },
  100. loginText: {
  101. color: 'white',
  102. }
  103. });
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement