fix: slide flickering
This commit is contained in:
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}
|
||||
|
||||
Reference in new issue
Block a user