Advertisement
joygabriel21

Event Handler

Jan 22nd, 2020
110
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.26 KB | None | 0 0
  1. import React, { Component } from "react";
  2. import { Button, StyleSheet, TextInput, View } from "react-native";
  3.  
  4. export default class App extends Component {
  5. state = {
  6. email: "",
  7. password: ""
  8. };
  9.  
  10. constructor(props) {
  11. super(props);
  12. this.handleChangeEmail = this.handleChangeEmail.bind(this)
  13. this.handleChangePassword = this.handleChangePassword.bind(this);
  14. this.handleLoginPress = this.handleLoginPress.bind(this);
  15. }
  16.  
  17. handleChangeEmail(text) {
  18. this.setState({
  19. email: text
  20. });
  21. }
  22.  
  23. handleChangePassword(text) {
  24. this.setState({
  25. password: text
  26. });
  27. }
  28.  
  29. handleLoginPress() {
  30. alert(
  31. `Your email: ${this.state.email}. And your password: ${
  32. this.state.password
  33. }`
  34. );
  35. }
  36.  
  37. render() {
  38. return (
  39. <View style={styles.container}>
  40. <TextInput
  41. onChangeText={this.handleChangeEmail}
  42. placeholder={"user@email.com"}
  43. style={styles.textInput}
  44. />
  45. <TextInput
  46. onChangeText={this.handleChangePassword}
  47. secureTextEntry={true}
  48. placeholder={"Your super secret password"}
  49. style={styles.textInput}
  50. />
  51. <Button title={"Login"} onPress={this.handleLoginPress} />
  52. </View>
  53. );
  54. }
  55. }
  56.  
  57. const styles = StyleSheet.create({
  58. container: {
  59. flex: 1,
  60. backgroundColor: "#F5FCFF",
  61. justifyContent: "center",
  62. alignItems: "center"
  63. },
  64. welcome: {
  65. fontSize: 20,
  66. textAlign: "center",
  67. margin: 10
  68. },
  69. textInput: {
  70. borderWidth: 1,
  71. borderColor: "mediumaquamarine",
  72. height: 45,
  73. width: 300,
  74. padding: 5,
  75. marginBottom: 22
  76. }
  77. });
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement