-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathHorizontalFlatList.js
More file actions
198 lines (192 loc) · 5.25 KB
/
HorizontalFlatList.js
File metadata and controls
198 lines (192 loc) · 5.25 KB
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
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
import React, { useCallback, PureComponent } from "react";
import { View, Text, FlatList, TouchableOpacity, Image } from "react-native";
import { Badge } from "@rneui/themed";
import { useNavigation } from "@react-navigation/native";
const HorizontalFlatList = ({
data,
level2Text,
level3Text,
level4Text,
dataType,
navigationDestination,
origin,
series_id,
}) => {
const navigation = useNavigation();
const renderItem = useCallback(
({ item }) => {
if (item.adult) {
// If item.adult is true, return null to skip rendering the item
return null;
}
return (
<Item
item={item}
dataType={dataType}
level2Text={level2Text}
level3Text={level3Text}
level4Text={level4Text}
navigation={navigation}
navigationDestination={navigationDestination}
origin={origin}
series_id={series_id}
/>
);
},
[
dataType,
navigation,
navigationDestination,
origin,
level2Text,
level3Text,
level4Text,
series_id,
]
);
return (
<FlatList
className="mb-4 bg-teal-500"
data={data}
initialNumToRender={5}
maxToRenderPerBatch={7}
updateCellsBatchingPeriod={1000}
horizontal // Set the horizontal prop to true
showsHorizontalScrollIndicator={false} // Optional: hide the horizontal scroll indicator
keyExtractor={(item) => {
if (dataType.includes("person")) {
return item.credit_id.toString();
} else {
return item.id.toString();
}
}}
renderItem={renderItem}
/>
);
};
class Item extends PureComponent {
render() {
const {
item,
dataType,
navigation,
navigationDestination,
origin,
series_id,
level2Text,
level3Text,
level4Text,
} = this.props;
const seriesId = dataType === "show" ? item.id : series_id;
const role = dataType.includes("cast") ? item.character : item.job;
const header = dataType === "movie" ? item.title : item.name;
const poster = dataType.includes("person")
? item.profile_path
: dataType === "episode"
? item.still_path
: item.poster_path;
const human = dataType.includes("person") ? true : false;
const date =
dataType === "movie"
? item.release_date
: dataType === "season"
? item.air_date
: item.first_air_date;
// let id;
// switch (dataType) {
// case "person":
// // code block
// id = item.id;
// break;
// case "season":
// // code block
// id = series_id;
// break;
return (
<TouchableOpacity
className="items-center py-3 mx-1 border-2 border-violet-800 rounded-lg w-[180]"
onPress={() => {
// console.log(
// "navigationDestination:",
// navigationDestination,
// "origin:",
// origin,
// "person_id: ",
// dataType.includes("person") ? item.id : null,
// "header: ",
// header
// );
navigation.push(navigationDestination, {
header: header,
series_id: seriesId,
season_number: item.season_number,
origin: origin,
person_id: dataType.includes("person") ? item.id : null,
movie_id: item.id,
// season_number: season_number,
episode_number: item.episode_number,
});
}}
>
{poster ? (
<Image
source={{
uri: `https://image.tmdb.org/t/p/w185/${poster}`,
}}
className="w-5/6 h-60"
/>
) : !human ? (
<Image
source={require("./assets/blank.png")}
className="w-5/6 h-60"
/>
) : (
<Image
source={require("./assets/blank_avatar.jpg")}
className="w-5/6 h-60"
/>
)}
<Text className="text-base font-bold text-center text-blue-800">
{header}
</Text>
{level2Text ? (
<Text className="text-sm font-bold text-center text-[#0d253f]">
{role}
</Text>
) : null}
{level3Text ? (
<View className="flex flex-row items-center justify-evenly">
{date ? (
<Text className="w-1/3 text-sm font-medium text-violet-800">
{date.split("-")[0]}
</Text>
) : null}
<Badge
value={item.vote_average}
status={
item.vote_average > 8
? "success"
: item.vote_average > 4
? "warning"
: "error"
}
badgeStyle={{ height: 22 }}
textStyle={{
fontSize: 15,
fontWeight: "bold",
color: "black",
}}
className="w-1/3"
/>
</View>
) : null}
{level4Text ? (
<Text className="text-base font-bold">
Episodes: {item.episode_count}
</Text>
) : null}
</TouchableOpacity>
);
}
}
export default HorizontalFlatList;