Skip to content

Commit

Permalink
Merge pull request #364 from MovieReviewComment/fix/issue-363/adjust-…
Browse files Browse the repository at this point in the history
…offset-on-resize
  • Loading branch information
2wheeh authored May 10, 2024
2 parents d4b5419 + 89724a3 commit 901af6a
Showing 1 changed file with 15 additions and 1 deletion.
16 changes: 15 additions & 1 deletion ui/src/hooks/common/use-swiper.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
'use client';

import { useRef, useState } from 'react';
import { useEffect, useRef, useState } from 'react';

import { useStateRef } from '@/hooks/common/use-state-ref';

Expand Down Expand Up @@ -144,6 +144,20 @@ export function useSwiper() {
setOffsetX(-(containerWidthRef.current * idx));
};

useEffect(() => {
const resizeHandler = () => {
const containerEl = containerRef.current!;
const containerWidth = containerEl.offsetWidth;

containerEl.classList.add('transition-none');
setOffsetX(-(containerWidth * currentIdx));
containerEl.classList.remove('transition-none');
};

window.addEventListener('resize', resizeHandler);
return () => window.removeEventListener('resize', resizeHandler);
}, [currentIdx, setOffsetX]);

return {
offsetX,
onTouchStart,
Expand Down

0 comments on commit 901af6a

Please sign in to comment.