smooth out the skeleton fades a bit more

This commit is contained in:
Emi Matchu 2020-09-15 05:29:28 -07:00
parent 956580c651
commit 8e97355499

View file

@ -120,7 +120,7 @@ function ItemPageHeader({ itemId, isEmbedded }) {
alignItems="stretch" alignItems="stretch"
justifyContent="center" justifyContent="center"
> >
<Delay ms={2000}> <Delay ms={500}>
<SkeletonText noOfLines={numDescriptionLines} spacing="4" /> <SkeletonText noOfLines={numDescriptionLines} spacing="4" />
</Delay> </Delay>
</Box> </Box>
@ -461,7 +461,7 @@ function ItemPageOutfitPreview({ itemId }) {
/** /**
* SubtleSkeleton hides the skeleton animation until a second has passed, and * SubtleSkeleton hides the skeleton animation until a second has passed, and
* doesn't fade in the content if it loads before then. This helps avoid * doesn't fade in the content if it loads near-instantly. This helps avoid
* flash-of-content stuff! * flash-of-content stuff!
* *
* For plain Skeletons, we often use <Delay><Skeleton /></Delay> instead. But * For plain Skeletons, we often use <Delay><Skeleton /></Delay> instead. But
@ -469,19 +469,30 @@ function ItemPageOutfitPreview({ itemId }) {
* placeholder content for layout: we don't want the delay if the content * placeholder content for layout: we don't want the delay if the content
* really _is_ present! * really _is_ present!
*/ */
function SubtleSkeleton({ ...props }) { function SubtleSkeleton({ isLoaded, ...props }) {
const [shouldFadeIn, setShouldFadeIn] = React.useState(false);
const [shouldShowSkeleton, setShouldShowSkeleton] = React.useState(false); const [shouldShowSkeleton, setShouldShowSkeleton] = React.useState(false);
React.useEffect(() => { React.useEffect(() => {
const t = setTimeout(() => setShouldShowSkeleton(true), 1000); const t = setTimeout(() => {
if (!isLoaded) {
setShouldFadeIn(true);
}
}, 150);
return () => clearTimeout(t);
});
React.useEffect(() => {
const t = setTimeout(() => setShouldShowSkeleton(true), 500);
return () => clearTimeout(t); return () => clearTimeout(t);
}); });
return ( return (
<Skeleton <Skeleton
fadeDuration={shouldFadeIn ? undefined : 0}
startColor={shouldShowSkeleton ? undefined : "transparent"} startColor={shouldShowSkeleton ? undefined : "transparent"}
endColor={shouldShowSkeleton ? undefined : "transparent"} endColor={shouldShowSkeleton ? undefined : "transparent"}
fadeDuration={shouldShowSkeleton ? undefined : 0} isLoaded={isLoaded}
{...props} {...props}
/> />
); );