Advertisement
nashci96

registertestta.js

Feb 27th, 2019
129
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.28 KB | None | 0 0
  1. import React, { Component } from 'react';
  2. import {
  3. AppRegistry,
  4. StyleSheet,
  5. Text,
  6. View,
  7. Button,
  8. TextInput,
  9. TouchableOpacity
  10. } from 'react-native';
  11.  
  12. export default class register extends Component {
  13. static navigationOptions= ({navigation}) =>({
  14. title: 'Register',
  15. headerRight:
  16. <TouchableOpacity
  17. onPress={()=>navigation.navigate('Home')}
  18. style={{margin:10,backgroundColor:'orange',padding:10}}>
  19. <Text style={{color:'#ffffff'}}>Home</Text>
  20. </TouchableOpacity>
  21. });
  22.  
  23. constructor(props){
  24. super(props)
  25. this.state={
  26. userName:'',
  27. userEmail:'',
  28. userPassword:''
  29. }
  30. }
  31.  
  32. userRegister = () =>{
  33. const {userName} = this.state;
  34. const {userEmail} = this.state;
  35. const {userPassword} = this.state;
  36.  
  37. fetch('http://10.44.1.27/testa/register.php',
  38. {
  39. method: 'post',
  40. header: {
  41. 'Accept' : 'application/json',
  42. 'Content-type' : 'application/json'
  43. },
  44. body:JSON.stringify({
  45. name: userName,
  46. email: userEmail,
  47. password: userPassword,
  48. })
  49.  
  50. })
  51. .then((response) => response.json())
  52. .then((responseJson) =>{
  53. alert(responseJson);
  54. })
  55. .catch((error) =>{
  56. console.error(error);
  57. });
  58. }
  59.  
  60. render() {
  61. return (
  62. <View style={styles.container}>
  63.  
  64. <TextInput
  65. placeholder="Enter Name"
  66. style={{width:250,margin:10,borderColor:"#333",borderWidth:1}}
  67. underlineColorAndroid="transparent"
  68. onChangeText= {userName => this.setState({userName})} />
  69.  
  70. <TextInput
  71. placeholder="Enter Email"
  72. style={{width:250,margin:10,borderColor:"#333",borderWidth:1}}
  73. underlineColorAndroid="transparent"
  74. onChangeText= {userEmail => this.setState({userEmail})} />
  75.  
  76. <TextInput
  77. placeholder="Enter Password"
  78. style={{width:250,margin:10,borderColor:"#333",borderWidth:1}}
  79. underlineColorAndroid="transparent"
  80. onChangeText= {userPassword => this.setState({userPassword})} />
  81.  
  82. <TouchableOpacity
  83. onPress={this.userRegister}
  84. style={{width:250,padding:10,backgroundColor:'magenta',alignItems:'center'}}>
  85. <Text style={{color:'#fff'}}>Signup</Text>
  86. </TouchableOpacity>
  87.  
  88. </View>
  89. );
  90. }
  91. }
  92.  
  93. const styles = StyleSheet.create({
  94. container: {
  95. flex: 1,
  96. justifyContent : 'center',
  97. alignItems: 'center',
  98. backgroundColor: '#F5FCFF',
  99. },
  100.  
  101. welcome: {
  102. fontSize: 20,
  103. textAlign: 'center',
  104. margin: 10,
  105. },
  106.  
  107. instruction: {
  108. textAlign: 'center',
  109. color: '#333333',
  110. marginBottom: 5,
  111. },
  112.  
  113.  
  114. });
  115.  
  116. AppRegistry.registerComponent('register', () => Register);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement