import React, { useEffect, useRef } from 'react';
import { Animated, Easing, View } from 'react-native';
const VbeSkeleton = ({
style,
color="rgba(0, 10, 20, 0.1)",
layout=[],
widthList=["100%"],
height=16,
margin={},
borderRadius=8,
animate=true,
isLoading=true,
children
}) => {
const opacity = useRef(new Animated.Value(1)).current;
useEffect(() => {
if (animate) {
startScanAnimate()
}
}, [animate])
const startScanAnimate = () => {
Animated.timing(opacity, {
toValue: 0.1,
duration: 1000,
easing: Easing.linear,
useNativeDriver: true
}).start(() => {
if (animate) {
endScanAnimate();
}
});
}
const endScanAnimate = () => {
Animated.timing(opacity, {
delay: 200,
toValue: 1,
duration: 1000,
easing: Easing.linear,
useNativeDriver: true
}).start(() => {
if (animate) {
startScanAnimate();
}
});
}
if (isLoading) {
if (layout.length > 0) {
return (
{ layout.map((item, index) =>
)}
)
} else {
return (
{ widthList.map((item, index) =>
)}
);
}
} else if (children) {
return children;
}
};
export default VbeSkeleton;