129 lines
3.4 KiB
TypeScript
129 lines
3.4 KiB
TypeScript
import React from "react";
|
|
import {
|
|
ActivityIndicator,
|
|
FlatList,
|
|
RefreshControl,
|
|
StyleSheet,
|
|
Text,
|
|
View,
|
|
} from "react-native";
|
|
import { moderateScale, verticalScale } from "react-native-size-matters";
|
|
|
|
import { Colors } from "@/theme";
|
|
import type { CollectionRendererProps } from "../../types/renderer.types";
|
|
|
|
export function CollectionScaffold(
|
|
props: CollectionRendererProps & { header?: React.ReactNode; countLabel?: string },
|
|
) {
|
|
return (
|
|
<FlatList
|
|
data={props.items}
|
|
keyExtractor={(item) => item.id}
|
|
keyboardShouldPersistTaps="handled"
|
|
removeClippedSubviews
|
|
initialNumToRender={12}
|
|
maxToRenderPerBatch={12}
|
|
windowSize={9}
|
|
style={styles.list}
|
|
contentContainerStyle={styles.content}
|
|
ListHeaderComponent={
|
|
<>
|
|
{props.header}
|
|
<Text style={styles.resultCount} accessibilityLiveRegion="polite">
|
|
{props.countLabel ?? `${props.total} ${props.total === 1 ? "result" : "results"}`}
|
|
</Text>
|
|
</>
|
|
}
|
|
ItemSeparatorComponent={() => <View style={styles.separator} />}
|
|
renderItem={({ item }) => (
|
|
<View style={styles.card}>
|
|
{props.renderItem({
|
|
item,
|
|
onPress: () => props.onItemPress(item),
|
|
})}
|
|
</View>
|
|
)}
|
|
onEndReached={props.onLoadMore}
|
|
onEndReachedThreshold={0.5}
|
|
refreshControl={
|
|
<RefreshControl refreshing={props.isRefreshing} onRefresh={props.onRefresh} />
|
|
}
|
|
ListEmptyComponent={
|
|
props.isLoading ? (
|
|
<View style={styles.stateCard}>
|
|
<ActivityIndicator />
|
|
<Text style={styles.stateText}>Loading content…</Text>
|
|
</View>
|
|
) : (
|
|
<View style={styles.stateCard}>
|
|
<Text style={styles.emptyTitle}>No content available</Text>
|
|
<Text style={styles.stateText}>No matching published content was found.</Text>
|
|
</View>
|
|
)
|
|
}
|
|
ListFooterComponent={
|
|
props.isFetchingNextPage ? (
|
|
<View style={styles.footerLoader}>
|
|
<ActivityIndicator />
|
|
</View>
|
|
) : null
|
|
}
|
|
/>
|
|
);
|
|
}
|
|
|
|
const styles = StyleSheet.create({
|
|
list: {
|
|
flex: 1,
|
|
backgroundColor: "#F6F8F7",
|
|
},
|
|
content: {
|
|
paddingHorizontal: moderateScale(18),
|
|
paddingTop: verticalScale(16),
|
|
paddingBottom: verticalScale(32),
|
|
},
|
|
resultCount: {
|
|
fontSize: moderateScale(12),
|
|
fontWeight: "700",
|
|
color: Colors.textSecondary,
|
|
letterSpacing: 0.2,
|
|
marginBottom: verticalScale(8),
|
|
marginLeft: moderateScale(4),
|
|
},
|
|
card: {
|
|
backgroundColor: "#FFFFFF",
|
|
borderRadius: moderateScale(18),
|
|
borderWidth: 1,
|
|
borderColor: "#D7E9DE",
|
|
overflow: "hidden",
|
|
},
|
|
separator: {
|
|
height: verticalScale(12),
|
|
},
|
|
stateCard: {
|
|
alignItems: "center",
|
|
justifyContent: "center",
|
|
backgroundColor: "#FFFFFF",
|
|
borderRadius: moderateScale(18),
|
|
borderWidth: 1,
|
|
borderColor: "#E2EAE5",
|
|
paddingHorizontal: moderateScale(20),
|
|
paddingVertical: verticalScale(28),
|
|
gap: verticalScale(8),
|
|
},
|
|
emptyTitle: {
|
|
fontSize: moderateScale(15),
|
|
fontWeight: "700",
|
|
color: Colors.textPrimary,
|
|
},
|
|
stateText: {
|
|
fontSize: moderateScale(13),
|
|
color: Colors.textSecondary,
|
|
textAlign: "center",
|
|
},
|
|
footerLoader: {
|
|
paddingVertical: verticalScale(18),
|
|
alignItems: "center",
|
|
},
|
|
});
|