-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathall-posts.js
48 lines (44 loc) · 1.22 KB
/
all-posts.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
import React from 'react';
import { View, FlatList, StyleSheet, Text, Dimensions } from 'react-native';
import { Post } from './Post';
const { screenWidth, screenHeight } = Dimensions.get('window');
export function AllPosts({ navigation, route }) {
const { posts, id } = route.params;
const listRef = React.useRef(null);
const onScrollToIndexFailed = (info) => {
console.log('======onScrollToIndexFailed=====', info);
};
const getItemLayout = React.useCallback((data, index) => {
return { length: 519, offset: 519 * index, index };
});
return (
<View style={styles.container}>
<FlatList
ref={listRef}
initialScrollIndex={id}
getItemLayout={getItemLayout}
onScrollToIndexFailed={onScrollToIndexFailed}
data={posts}
renderItem={({ item }) => (
<View style={styles.element} key={item.id}>
<Post img={item.img} type="all" />
<View>
<Text>Liked by</Text>
</View>
<View>
<Text>{item.date}</Text>
</View>
</View>
)}
/>
</View>
);
}
const styles = StyleSheet.create({
container: {
flex: 1,
},
element: {
marginBottom: 100,
},
});