Advertisement
Guest User

Untitled

a guest
Feb 23rd, 2019
67
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.09 KB | None | 0 0
  1. <FlatList data={this.state.mdata}
  2. renderItem={this.renderList}
  3. keyExtractor={(item, index) => `${index}`}
  4. horizontal={false} numColumns={2}/>
  5.  
  6. import {Text, View, ScrollView, TouchableOpacity,StyleSheet,Dimensions,FlatList} from 'react-native';
  7. import {Card}from 'react-native-elements';
  8. import API from './axios';
  9. const styles = StyleSheet.create({
  10. image: {
  11. flex:1,width:'50%',height:'50%',
  12. alignItems: 'center',
  13. justifyContent: 'center',
  14. },
  15.  
  16. })
  17.  
  18. export default class ImageList extends React.Component {
  19.  
  20. constructor(props) {
  21. super(props);
  22. this.state = {
  23. mloading: false,
  24. mdata: [],
  25. current_page: 1,
  26. merror: null,
  27. mhasMore: true
  28. }
  29. }
  30. componentDidMount() { this.getListOfPictures(); }
  31.  
  32. render() {
  33. return (
  34.  
  35. <FlatList
  36. data={this.state.mdata}
  37. renderItem={this.renderList}
  38. keyExtractor={(item, index) => `${index}`}
  39. horizontal={false} numColumns={2}/>
  40.  
  41. )
  42. }
  43.  
  44.  
  45. /********************************************************************************
  46. * getListOfPictures All pictures for dashboard
  47. ********************************************************************************/
  48. getListOfPictures = () => {
  49. if (this.state.mloading) { return; }
  50. this.setState({ mloading: true });
  51.  
  52. API.get(`dashboard/all`)
  53. .then(res => {
  54. console.log("reco1m",res.data.recommendations[0]);
  55. const nextPictures= res.data.recommendations.map(data => ({
  56. title: data.style,
  57. image_url: data.img,
  58. description: data.description,
  59. id: data.style
  60. }));
  61. console.log(nextPictures);
  62. this.setState({
  63. mhasMore: true,
  64. mdata: [...this.state.mdata, ...nextPictures],
  65. mloading: false,
  66. current_page: this.state.current_page + 1})
  67. }).catch(error => {this.setState({ merror:error, mloading: false });});
  68. }
  69.  
  70. isCloseToBottom({ layoutMeasurement, contentOffset, contentSize }) {
  71. return layoutMeasurement.height + contentOffset.y
  72. >= contentSize.height - 0;
  73. }
  74.  
  75. renderList = () => {
  76. return ( this.state.mdata.map((u) => {
  77. return (
  78. <View style={{flex: 0.5, height: 150, margin: 5}}>
  79. <TouchableOpacity
  80. key={u.id} >
  81. <Card
  82. featuredTitle={u.title}
  83. image={{ uri: u.image_url }}
  84. imageStyle={styles.image}>
  85. <View style={{ padding: 10 }}>
  86. <Text style={{ fontSize: 15}}>Description:</Text>
  87. <Text>{u.description}</Text>
  88. </View>
  89. </Card>
  90. </TouchableOpacity>
  91. </View>
  92. );
  93. }))
  94. }
  95.  
  96.  
  97. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement