fix: slide flickering

This commit is contained in:
ner committed 2024-11-07 17:00:45 +02:00
1 parent af942149af
commit 418ab2cf15
4 files changed
+27 -42

No files matched your search

@@ -21,31 +21,27 @@ interface Props extends Context {
const Carousel = memo(
function Carousel({ shows, gap = 8, onIndexChange, onEndReached }: Props) {
const initialRef = useRef(true);
const index = useSilentIndex();
const [loaded, setLoaded] = useState(!index);
const context = useMemo(
() => ({
onIndexChange,
onIndexChange: (next: number) => {
onIndexChange(next);
if (loaded || next === index) return;
startTransition(() => setLoaded(true));
},
gap
}),
[onIndexChange, gap]
[onIndexChange, gap, loaded, index]
);
const handleScroll = () => {
if (loaded) return;
if (initialRef.current) return (initialRef.current = false);
startTransition(() => setLoaded(true));
};
return (
<div className='card-aspect-ratio relative mx-auto'>
{!loaded && <Poster lazy={false} show={shows![index]} className='pointer-events-none absolute left-0 top-0' />}
<Virtuoso
onScroll={handleScroll}
initialItemCount={1}
horizontalDirection
skipAnimationFrameInResizeObserver={true}
+15 -18
View File
@@ -12,24 +12,21 @@ interface Props {
}
const Poster: FC<Props> = ({ show, onClick, className, lazy = true }) => (
<div className={cn('card-aspect-ratio relative bg-black overflow-hidden rounded-lg text-lg', className)}>
<div className='flex size-full'>
<picture>
<source srcSet={show.poster['1x']} media='(max-resolution: 191dpi)' />
<source srcSet={show.poster['1x']} media='(max-device-pixel-ratio: 1.99)' />
<source srcSet={show.poster['1.5x']} media='(min-resolution: 192dpi)' />
<source srcSet={show.poster['1.5x']} media='(min-device-pixel-ratio: 2)' />
<img
className='size-full rounded-lg object-cover md:rounded-none md:rounded-l-lg'
loading={lazy ? 'lazy' : 'eager'}
src={show.poster['1x']}
alt={show.title}
/>
</picture>
</div>
<div className='absolute left-0 top-0 flex size-full flex-col justify-between rounded-md bg-vignette p-2 text-white md:rounded-none md:rounded-l-lg'>
<Handlers show={show} onClick={onClick} />
</div>
<div
className={cn(
'card-aspect-ratio relative bg-black overflow-hidden rounded-lg text-lg',
'after:block after:absolute after:left-0 after:top-0 after:size-full after:bg-vignette',
className
)}
>
<picture className='size-full rounded-lg object-cover md:rounded-none md:rounded-l-lg'>
<source srcSet={show.poster['1x']} media='(max-resolution: 191dpi)' />
<source srcSet={show.poster['1x']} media='(max-device-pixel-ratio: 1.99)' />
<source srcSet={show.poster['1.5x']} media='(min-resolution: 192dpi)' />
<source srcSet={show.poster['1.5x']} media='(min-device-pixel-ratio: 2)' />
<img className='size-full' loading={lazy ? 'lazy' : 'eager'} src={show.poster['1x']} alt={show.title} />
</picture>
<Handlers show={show} onClick={onClick} />
</div>
);
+1 -1
View File
@@ -57,7 +57,7 @@ const Preview: FC<Props> = ({ show: baseShow, showType, showId, className, poste
)}
</div>
<Actions className='order-1 mb-4 mt-1 md:order-2 md:mt-0' show={show} />
<Actions className='order-1 mb-4 md:order-2' show={show} />
<p key={show.id} className='order-4 md:order-4 md:line-clamp-3' title={show.overview}>
{show.overview}
+3 -11
View File
@@ -136,17 +136,9 @@
height: 450px;
flex-shrink: 0;
@media screen and (max-width: 600px) {
width: 100%;
height: 100%;
aspect-ratio: 2/3;
}
}
@supports (hanging-punctuation: first) and (font: -apple-system-body) and (-webkit-appearance: none) {
.card-aspect-ratio {
@media screen and (max-width: 600px) {
aspect-ratio: 1.35/2;
}
--width: calc(100vw - 1rem);
width: var(--width);
height: calc(var(--width) * 3 / 2);
}
}
}