Advertisement
Guest User

Untitled

a guest
Jul 30th, 2018
107
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.51 KB | None | 0 0
  1. import React, { Component } from "react";
  2. import {
  3. Container,
  4. Header,
  5. Content,
  6. Form,
  7. Item,
  8. Input,
  9. Label
  10. } from "native-base";
  11. import { TextInput, Button } from "react-native";
  12. import { auth, db } from "../firebaseconfig";
  13.  
  14. export default class FloatingLabelExample extends Component {
  15. state = {
  16. username: "",
  17. password: "",
  18. passwordConfirm: "",
  19. error: "",
  20. authUser: {}
  21. };
  22.  
  23. onUChange = e => {
  24. console.log("HERE");
  25. console.log(e);
  26. this.setState(
  27. {
  28. username: e
  29. },
  30. () => {}
  31. );
  32. console.log(this.state);
  33. };
  34.  
  35. onPChange = e => {
  36. console.log("HERE");
  37. console.log(e);
  38. this.setState(
  39. {
  40. password: e
  41. },
  42. () => {}
  43. );
  44. console.log(this.state);
  45. };
  46.  
  47. onPCChange = e => {
  48. console.log("HERE");
  49. console.log(e);
  50. this.setState(
  51. {
  52. passwordConfirm: e
  53. },
  54. () => {}
  55. );
  56. console.log(this.state);
  57. };
  58.  
  59. handleSubmit1 = () => {
  60. console.log(this.props);
  61. };
  62. handleSubmit = navigation => {
  63. const { username, password, passwordConfirm, error } = this.state;
  64.  
  65. auth
  66. .createUserWithEmailAndPassword(username, password)
  67. .then(res => res.json())
  68. .then(r =>
  69. this.setState(
  70. {
  71. authUser: r
  72. },
  73. () => {}
  74. )
  75. )
  76. .catch(e => {
  77. this.setState({
  78. error: e.message
  79. });
  80. });
  81.  
  82. this.props.navigation.navigate("Details", this.state.authUser);
  83. };
  84.  
  85. render() {
  86. const { username, password, passwordConfirm, error } = this.state;
  87.  
  88. const isInvalid =
  89. username == "" ||
  90. password == "" ||
  91. password.length == 0 ||
  92. password != passwordConfirm;
  93.  
  94. console.log(this.props);
  95.  
  96. return (
  97. <Form>
  98. <TextInput
  99. style={{ height: 40 }}
  100. placeholder="Username"
  101. name="username"
  102. onChangeText={this.onUChange}
  103. />
  104.  
  105. <TextInput
  106. style={{ height: 40 }}
  107. placeholder="Password"
  108. name="password"
  109. onChangeText={this.onPChange}
  110. />
  111.  
  112. <TextInput
  113. style={{ height: 40 }}
  114. placeholder="Confirm Password"
  115. name="passwordConfirm"
  116. onChangeText={this.onPCChange}
  117. />
  118.  
  119. <Button
  120. onPress={this.handleSubmit}
  121. title="Submit"
  122. disabled={isInvalid}
  123. />
  124. </Form>
  125. );
  126. }
  127. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement