Obanana_test/app/layout/skeleton/cardSkeleton.jsx

111 lines
2.8 KiB
React
Raw Permalink Normal View History

2024-02-12 08:58:57 +08:00
import React, { useState, useEffect } from "react";
import { View, Text, StyleSheet, Animated, ScrollView } from "react-native";
import MasonryList from "@react-native-seoul/masonry-list";
const CardSkeletonLoading = () => {
const [animation, setAnimation] = useState(new Animated.Value(0));
useEffect(() => {
Animated.loop(
Animated.timing(animation, {
toValue: 1,
duration: 900,
useNativeDriver: true,
})
).start();
}, [animation]);
const opacity = animation.interpolate({
inputRange: [0, 1],
outputRange: [0.2, 1],
});
const product = [1, 2, 3, 4, 5, 6];
return (
<View style={styles.container}>
<View style={styles.container1}>
<Animated.View style={[styles.skeletonText, { opacity }]} />
</View>
<View style={styles.categories}>
<Animated.View style={[styles.skeletonRound, { opacity }]} />
<Animated.View style={[styles.skeletonRound, { opacity }]} />
<Animated.View style={[styles.skeletonRound, { opacity }]} />
<Animated.View style={[styles.skeletonRound, { opacity }]} />
<Animated.View style={[styles.skeletonRound, { opacity }]} />
</View>
<ScrollView style={styles.container2}>
<Animated.View style={[styles.skeletonText, { opacity }]} />
<MasonryList
data={product}
keyExtractor={(item) => item.id}
style={styles.list}
numColumns={2}
showsVerticalScrollIndicator={false}
renderItem={({ item }) => (
<Animated.View style={[styles.skeleton, { opacity }]} />
)}
containerStyle={styles.container1}
contentContainerStyle={styles.content}
// refreshing={isLoadingNext}
// onRefresh={() => refetch({ first: itemCount })}
onEndReachedThreshold={0.1}
// onEndReached={() => loadNext(ITEM_CNT)}
/>
</ScrollView>
</View>
);
};
const styles = StyleSheet.create({
container: {
alignItems: "center",
justifyContent: "center",
flex: 1,
backgroundColor: "#fff",
},
container1: {
width: "100%",
marginTop: 0,
flex: 1,
backgroundColor: "#fff",
},
container2: {
width: "100%",
marginTop: 30,
flex: 1,
backgroundColor: "#fff",
},
categories: {
flexDirection: "row",
width: "100%",
justifyContent: "space-between",
},
skeleton: {
backgroundColor: "#f2f2f2",
borderRadius: 5,
width: "98%",
height: 250,
marginVertical: 5,
},
skeletonText: {
backgroundColor: "#f2f2f2",
borderRadius: 5,
width: "30%",
height: 30,
marginVertical: 5,
},
skeletonRound: {
backgroundColor: "#f2f2f2",
borderRadius: 5,
width: 60,
height: 60,
borderRadius: 80,
marginVertical: 5,
},
});
export default CardSkeletonLoading;