Advertisement
Guest User

app.js

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