Brak opisu

Home_page.js 2.2KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  1. import React, {useState, useEffect} from 'react'
  2. import { Button, Text, View, StyleSheet} from 'react-native'
  3. import {FlatList, ListViewBase } from 'react-native'
  4. import {TouchableOpacity} from 'react-native-gesture-handler'
  5. import {List, Divider} from 'react-native-paper'
  6. import Loading from '../components/Loading'
  7. import firebase from 'firebase';
  8. import { styles } from "../config/styles";
  9. import { TextInput, TouchableWithoutFeedback, Keyboard, ImageBackground} from "react-native";
  10. export default function Home_page({navigation}) {
  11. const [threads, setThreads] = useState([]);
  12. const [loading, setLoading] = useState(true);
  13. useEffect(() => {
  14. const fire = firebase.firestore()
  15. .collection('THREADS')
  16. .onSnapshot(querySnapshot => {
  17. const threads = querySnapshot.docs.map(documentSnapshot => {
  18. return{
  19. _id:documentSnapshot.id,
  20. name:'',
  21. ...documentSnapshot.data()
  22. };
  23. });
  24. setThreads(threads);
  25. if(loading){
  26. setLoading(false);
  27. }
  28. });
  29. return () => fire();
  30. }, []);
  31. if (loading) {
  32. return <Loading />;
  33. }
  34. return (
  35. <View>
  36. <ImageBackground style={styles.stdcontainer} source={require('../assets/yellow-white.jpg')}>
  37. <FlatList
  38. data={threads}
  39. keyExtractor = {item => item._id}
  40. ItemSeparatorComponent={() => <Divider />}
  41. renderItem = {({item}) => (
  42. <TouchableOpacity
  43. onPress={() => navigation.navigate('Room', {thread: item})}
  44. >
  45. <List.Item
  46. title={item.name}
  47. description='Item description'
  48. titleNumberOfLines={1}
  49. titleStyle={styles.listTitle}
  50. descriptionStyle={styles.listDescription}
  51. descriptionNumberOfLines={1}
  52. />
  53. </TouchableOpacity>
  54. )}
  55. />
  56. <Button
  57. title='Ver mensajes'
  58. onPress={() => navigation.navigate('Add')}
  59. />
  60. <Button
  61. title ='Hacer Busqueda'
  62. onPress= {() => navigation.navigate('Room')}
  63. />
  64. </ImageBackground>
  65. </View>
  66. );
  67. }