1- import { View } from "react-native" ;
2- import {
3- Fade ,
4- Placeholder ,
5- PlaceholderLine ,
6- PlaceholderMedia ,
7- } from "rn-placeholder " ;
1+ import { StyleSheet , View } from "react-native" ;
2+ import Animated , {
3+ useAnimatedStyle ,
4+ withRepeat ,
5+ withSequence ,
6+ withTiming ,
7+ } from "react-native-reanimated " ;
88
99interface SkeletonListProps {
1010 numberItems ?: number ;
@@ -13,19 +13,67 @@ interface SkeletonListProps {
1313export const SkeletonList = ( { numberItems = 10 } : SkeletonListProps ) => {
1414 const items = [ ] ;
1515
16+ const animatedStyle = useAnimatedStyle ( ( ) => {
17+ return {
18+ opacity : withRepeat (
19+ withSequence (
20+ withTiming ( 0.3 , { duration : 800 } ) ,
21+ withTiming ( 0.7 , { duration : 800 } ) ,
22+ ) ,
23+ - 1 ,
24+ true ,
25+ ) ,
26+ } ;
27+ } ) ;
28+
1629 for ( let i = 0 ; i < numberItems ; i ++ ) {
1730 items . push (
18- < Placeholder
19- Animation = { Fade }
31+ < View
2032 key = { `skeleton-${ i } ` }
21- Left = { PlaceholderMedia }
22- style = { { marginBottom : 12 } }
33+ style = { styles . itemContainer }
2334 >
24- < PlaceholderLine width = { 90 } />
25- < PlaceholderLine width = { 80 } />
26- </ Placeholder > ,
35+ < Animated . View style = { [ styles . media , animatedStyle ] } />
36+ < View style = { styles . content } >
37+ < Animated . View
38+ style = { [ styles . line , styles . longLine , animatedStyle ] }
39+ />
40+ < Animated . View
41+ style = { [ styles . line , styles . shortLine , animatedStyle ] }
42+ />
43+ </ View >
44+ </ View > ,
2745 ) ;
2846 }
2947
3048 return < View > { items } </ View > ;
3149} ;
50+
51+ const styles = StyleSheet . create ( {
52+ content : {
53+ flex : 1 ,
54+ } ,
55+ itemContainer : {
56+ alignItems : "center" ,
57+ flexDirection : "row" ,
58+ marginBottom : 12 ,
59+ } ,
60+ line : {
61+ backgroundColor : "#e1e1e1" ,
62+ borderRadius : 4 ,
63+ height : 12 ,
64+ marginVertical : 4 ,
65+ } ,
66+ longLine : {
67+ width : "90%" ,
68+ } ,
69+ media : {
70+ backgroundColor : "#e1e1e1" ,
71+ borderRadius : 20 ,
72+ height : 40 ,
73+ marginRight : 12 ,
74+ width : 40 ,
75+ } ,
76+ shortLine : {
77+ width : "80%" ,
78+ } ,
79+ } ) ;
0 commit comments