fix: slide flickering
This commit is contained in:
1 parent
af942149af
commit
418ab2cf15
4 files changed
+21
-36
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) => {
|
||||||
gap
|
onIndexChange(next);
|
||||||
}),
|
|
||||||
[onIndexChange, gap]
|
|
||||||
);
|
|
||||||
|
|
||||||
const handleScroll = () => {
|
if (loaded || next === index) return;
|
||||||
if (loaded) return;
|
|
||||||
|
|
||||||
if (initialRef.current) return (initialRef.current = false);
|
|
||||||
|
|
||||||
startTransition(() => setLoaded(true));
|
startTransition(() => setLoaded(true));
|
||||||
};
|
},
|
||||||
|
gap
|
||||||
|
}),
|
||||||
|
[onIndexChange, gap, loaded, index]
|
||||||
|
);
|
||||||
|
|
||||||
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}
|
||||||
|
|||||||
@@ -12,25 +12,22 @@ 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',
|
||||||
|
'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-resolution: 191dpi)' />
|
||||||
<source srcSet={show.poster['1x']} media='(max-device-pixel-ratio: 1.99)' />
|
<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-resolution: 192dpi)' />
|
||||||
<source srcSet={show.poster['1.5x']} media='(min-device-pixel-ratio: 2)' />
|
<source srcSet={show.poster['1.5x']} media='(min-device-pixel-ratio: 2)' />
|
||||||
<img
|
<img className='size-full' loading={lazy ? 'lazy' : 'eager'} src={show.poster['1x']} alt={show.title} />
|
||||||
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>
|
</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} />
|
<Handlers show={show} onClick={onClick} />
|
||||||
</div>
|
</div>
|
||||||
</div>
|
|
||||||
);
|
);
|
||||||
|
|
||||||
export default Poster;
|
export default Poster;
|
||||||
@@ -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
@@ -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;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in new issue
Block a user