Advertisement
Guest User

Untitled

a guest
Feb 21st, 2020
75
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.18 KB | None | 0 0
  1. import React, { Component } from 'react';
  2. import {
  3. View,
  4. ScrollView,
  5. Image,
  6. Text,
  7. TouchableHighlight,
  8. } from 'react-native';
  9. import firebase from 'react-native-firebase';
  10.  
  11. firebase.app();
  12.  
  13. class SympathyList extends Component {
  14. constructor(props) {
  15. super(props);
  16. this.state = { chats: [] };
  17. this.getChats = this.getChats.bind(this);
  18. }
  19.  
  20. componentDidMount() {
  21. var _userId = firebase.auth().currentUser.uid;
  22.  
  23. this.getChats(_userId);
  24. }
  25.  
  26. getChats = _userId => {
  27. var readedData = firebase.database().ref('chats/');
  28. readedData.on('value', snapshot => {
  29. this.setState({ chats: snapshot.val() });
  30. console.log(this.state.chats);
  31. });
  32. };
  33.  
  34. render() {
  35. const { navigate } = this.props.navigation;
  36. let allChats = Object.keys(this.state.chats).map(key => key);
  37.  
  38. return (
  39. <ScrollView style={{ backgroundColor: '#182343' }}>
  40. {allChats.map(rez => {
  41. <View
  42. style={{
  43. borderColor: 'gray',
  44. borderWidth: 1,
  45. flexDirection: 'row',
  46. backgroundColor: 'white',
  47. margin: 10,
  48. }}
  49. >
  50. <Image
  51. style={{ height: 50, width: 50 }}
  52. source={{
  53. uri: 'https://facebook.github.io/react/logo-og.png',
  54. }}
  55. />
  56. <Text style={{ padding: 12 }}>Persons Name</Text>
  57. <TouchableHighlight
  58. style={{ right: 0, position: 'absolute' }}
  59. title="Chat"
  60. onPress={() => navigate('Chat', { name: 'Chat' })}
  61. >
  62. <Text
  63. style={{
  64. color: 'white',
  65. backgroundColor: 'orange',
  66. height: 50,
  67. alignContent: 'center',
  68. padding: 12,
  69. borderColor: '#182343',
  70. borderWidth: 2,
  71. borderRadius: 5,
  72. }}
  73. >
  74. Chat
  75. </Text>
  76. </TouchableHighlight>
  77. </View>;
  78. })}
  79. </ScrollView>
  80. );
  81. }
  82. }
  83.  
  84. export default SympathyList;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement