Advertisement
Guest User

Untitled

a guest
Oct 20th, 2018
66
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.98 KB | None | 0 0
  1. import React, { Component } from 'react';
  2. import { View, Text, TouchableOpacity, TextInput, StyleSheet } from 'react-native';
  3. import firebase from 'react-native-firebase';
  4.  
  5. class CreateEvent extends Component {
  6.  
  7. constructor(props) {
  8. super(props);
  9. this.ref = firebase.firestore().collection('Events');
  10.  
  11. this.state = {
  12. name: '',
  13. description: '',
  14. phone: '',
  15. date: '',
  16. }
  17. }
  18.  
  19. handleName = (text) => {
  20. this.setState({name: text })
  21. }
  22. handleDescription = (text) => {
  23. this.setState({ description: text })
  24. }
  25. handlePhone = (number) => {
  26. this.setState({ phone: number })
  27. }
  28.  
  29. handleDate = (date) => {
  30. this.setState({ date: date })
  31. }
  32.  
  33. async sendToFirebase(name,description,creatorPhone,date) {
  34. this.ref.doc("56789").set({
  35. name,
  36. date: "2018-10-21T01:01:29Z",
  37. latitude: "41.3889301",
  38. longitude: "2.1170454",
  39. description,
  40. creatorPhone
  41. });
  42. }
  43.  
  44.  
  45. render() {
  46. const { name,description,creatorPhone,date } = this.state;
  47.  
  48. return (
  49. <View style = {styles.container}>
  50. <TextInput style = {styles.input}
  51. underlineColorAndroid = "transparent"
  52. placeholder = "Name"
  53. placeholderTextColor = "#9a73ef"
  54. autoCapitalize = "none"
  55. onChangeText = {this.handleName}/>
  56.  
  57. <TextInput style = {styles.input}
  58. underlineColorAndroid = "transparent"
  59. placeholder = "Description"
  60. placeholderTextColor = "#9a73ef"
  61. autoCapitalize = "none"
  62. onChangeText = {this.handleDesciption}/>
  63.  
  64.  
  65. <TextInput style = {styles.input}
  66. underlineColorAndroid = "transparent"
  67. placeholder = "Phone"
  68. placeholderTextColor = "#9a73ef"
  69. autoCapitalize = "none"
  70. onChangeText = {this.handlePhone}/>
  71.  
  72. <TextInput style = {styles.input}
  73. underlineColorAndroid = "transparent"
  74. placeholder = "date"
  75. placeholderTextColor = "#9a73ef"
  76. autoCapitalize = "none"
  77. onChangeText = {this.handleDate}/>
  78.  
  79.  
  80.  
  81. <TouchableOpacity
  82. onPress={() => this.sendToFirebase(name,description,creatorPhone,date)}
  83. style = {styles.submitButton}>
  84. <Text style = {styles.submitButtonText}> Submit </Text>
  85. </TouchableOpacity>
  86. </View>
  87. )
  88. }
  89. }
  90.  
  91. const styles = StyleSheet.create({
  92. container: {
  93. paddingTop: 23
  94. },
  95. input: {
  96. margin: 15,
  97. height: 40,
  98. borderColor: '#7a42f4',
  99. borderWidth: 1
  100. },
  101. submitButton: {
  102. backgroundColor: '#7a42f4',
  103. padding: 10,
  104. margin: 15,
  105. height: 40,
  106. },
  107. submitButtonText:{
  108. color: 'white'
  109. }
  110. });
  111.  
  112. export default CreateEvent;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement