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