-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathFunctional_recyler_list_view_working_App.js
109 lines (100 loc) · 2.71 KB
/
Functional_recyler_list_view_working_App.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
import React, {Component, useEffect, useState} from 'react';
import { StyleSheet, View, Dimensions, TouchableOpacity, Text, Image } from 'react-native';
import faker from 'faker';
import { RecyclerListView, DataProvider, LayoutProvider } from 'recyclerlistview';
const SCREEN_WIDTH = Dimensions.get('window').width;
const App = () => {
const fakeData = []
const [list , setList] = useState([])
for(let i = 0; i < 1000; i+= 1) {
fakeData.push({
type: 'NORMAL',
item: {
id: i,
image: `https://randomuser.me/api/portraits/${faker.helpers.randomize(['women', 'men'])}/${faker.random.number(60)}.jpg`,
name: faker.name.firstName(),
description: faker.random.words(10),
},
})
}
useEffect(() => {
setList(new DataProvider((r1, r2) => r1 !== r2).cloneWithRows(fakeData))
},[])
const layoutProvider = new LayoutProvider((i) => {
return list.getDataForIndex(i).type;
}, (type, dim) => {
switch (type) {
case 'NORMAL':
dim.width = SCREEN_WIDTH;
dim.height = 100;
break;
default:
dim.width = 0;
dim.height = 0;
break;
};
})
const rowRenderer = (type, data) => {
const { image, name, description, id} = data.item;
return (
<TouchableOpacity style={styles.listItem} onPress={() => console.log('Pressed')}>
<Image style={styles.image} source={{ uri:image }} />
<View style={styles.body}>
<Text style={styles.name}>{name}{" "} {id}</Text>
<Text style={styles.description}>{description}</Text>
</View>
</TouchableOpacity>
)
}
if(list.length === 0){
return(
<View style={{flex:1, alignItems:"center", justifyContent:"center"}}>
<Text style={{color:"black"}}>loading</Text>
</View>
)
}
return (
<View style={styles.container}>
<RecyclerListView
style={{flex: 1}}
rowRenderer={rowRenderer}
dataProvider={list}
layoutProvider={layoutProvider}
renderAheadOffset={500 }
/>
</View>
);
}
export default App;
const styles = StyleSheet.create({
container: {
flex: 1,
backgroundColor: '#FFF',
minHeight: 1,
minWidth: 1,
},
body: {
marginLeft: 10,
marginRight: 10,
maxWidth: SCREEN_WIDTH - (80 + 10 + 20),
},
image: {
height: 80,
width: 80,
borderRadius:80
},
name: {
fontSize: 20,
fontWeight: 'bold',
},
description: {
fontSize: 14,
opacity: 0.5,
},
listItem: {
flexDirection: 'row',
margin: 5,
borderRadius:10,
backgroundColor:"#F0F0F0"
},
});