Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import React, { Component } from 'react';
- import {
- StyleSheet,
- Text,
- View,
- TextInput,
- TouchableHighlight,
- } from 'react-native';
- export default class LoginView extends Component {
- constructor(props) {
- super(props);
- this.state = {
- email:"",
- password:"",
- }
- }
- validateEmail = (email) => {
- 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,}))$/;
- return checkEmail.test(email);
- };
- submitForm = () => {
- const { email, password } = this.state;
- if(email.trim() === '' || password.trim() === '' || !this.validateEmail(email)){
- console.log('error')
- return
- }
- console.log('cool its ok')
- //now you can send it to your server
- }
- render() {
- return (
- <View style={styles.container}>
- <View style={styles.inputContainer}>
- <TextInput style={styles.inputs}
- placeholder="Email"
- keyboardType="email-address"
- underlineColorAndroid='transparent'
- onChangeText={(email) => this.setState({email})}/>
- </View>
- <View style={styles.inputContainer}>
- <TextInput style={styles.inputs}
- placeholder="Password"
- secureTextEntry={true}
- underlineColorAndroid='transparent'
- onChangeText={(password) => this.setState({password})}/>
- </View>
- <TouchableHighlight style={[styles.buttonContainer, styles.loginButton]} onPress={this.submitForm}>
- <Text style={styles.loginText}>Login</Text>
- </TouchableHighlight>
- </View>
- );
- }
- }
- const styles = StyleSheet.create({
- container: {
- flex: 1,
- justifyContent: 'center',
- alignItems: 'center',
- backgroundColor: '#DCDCDC',
- },
- inputContainer: {
- borderBottomColor: '#F5FCFF',
- backgroundColor: '#FFFFFF',
- borderRadius:30,
- borderBottomWidth: 1,
- width:250,
- height:45,
- marginBottom:20,
- flexDirection: 'row',
- alignItems:'center'
- },
- inputs:{
- height:45,
- marginLeft:16,
- borderBottomColor: '#FFFFFF',
- flex:1,
- },
- buttonContainer: {
- height:45,
- flexDirection: 'row',
- justifyContent: 'center',
- alignItems: 'center',
- marginBottom:20,
- width:250,
- borderRadius:30,
- },
- loginButton: {
- backgroundColor: "#00b5ec",
- },
- loginText: {
- color: 'white',
- }
- });
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement