Created
June 9, 2018 23:11
-
-
Save alexpaul/4a020d3072befc15dc38cbd67b6b5e88 to your computer and use it in GitHub Desktop.
A basic login component with two TextInput's and a TouchableHighLight
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import React, { Component } from 'react' | |
| import { View, | |
| TextInput, | |
| Text, | |
| Alert, | |
| TouchableHighlight, | |
| StyleSheet } from 'react-native' | |
| export default class Login extends Component { | |
| constructor(props) { | |
| super(props) | |
| this.state = {text: '', | |
| password: '' | |
| } | |
| } | |
| updateEmail = (email) => { | |
| this.setState({email: email}) | |
| } | |
| updatePassword = (password) => { | |
| this.setState({password: password}) | |
| } | |
| loginPress = (email) => { | |
| Alert.alert('Please verify your email: \n' + email) | |
| } | |
| render() { | |
| return( | |
| <View style={styles.loginView}> | |
| <TextInput | |
| style={styles.input} | |
| placeholder='Email' | |
| autoCapitalize='none' | |
| onChangeText={this.updateEmail} | |
| clearButtonMode='while-editing' | |
| /> | |
| <TextInput | |
| style={styles.input} | |
| placeholder='Password' | |
| onChangeText={this.updatePassword} | |
| secureTextEntry={true} | |
| /> | |
| <TouchableHighlight | |
| style={styles.button} | |
| onPress={() => this.loginPress(this.state.email, this.state.password)} | |
| underlayColor='white' | |
| > | |
| <Text style={styles.buttonText}>Login</Text> | |
| </TouchableHighlight> | |
| </View> | |
| ) | |
| } | |
| } | |
| const styles = StyleSheet.create({ | |
| loginView: { | |
| height: '50%', | |
| width: '90%', | |
| backgroundColor: 'orange', | |
| alignItems: 'center', | |
| }, | |
| input: { | |
| marginTop: 40, | |
| padding: 10, | |
| backgroundColor: 'white', | |
| height: 44, | |
| width: '90%' | |
| }, | |
| button: { | |
| marginTop: 20, | |
| backgroundColor: 'limegreen', | |
| height: 44, | |
| width: '90%', | |
| alignItems: 'center', | |
| justifyContent: 'center' | |
| }, | |
| buttonText: { | |
| color: 'white', | |
| fontSize: 20, | |
| fontWeight: '900', | |
| } | |
| }) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment