Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: useDragIndexCarousel Infinity mode추가, useInterval 훅 추가 #3

Merged
merged 6 commits into from
May 10, 2024

Conversation

d0422
Copy link
Member

@d0422 d0422 commented May 10, 2024

  • useDragIndexCarousel infinity mode 추가
  • useInterval 훅 추가

infinity mode추가

drag Carousel 에 infinity mode를 추가하였습니다.

2024-05-10.13-07-18.mp4

요소 앞뒤로 최후방요소와 최상단 요소를 복사하여 각각 추가하고, index를 translate계산할때에 적용하여 자연스럽게 보일 수 있도록 처리했습니다.

최후방요소에 도달한 경우

  1. transition 옵션을 none으로 지정하여 유저가 transform조정을 알아챌 수 없도록 함
  2. translate를 최초 인덱스 +1만큼 이동하여 위치 이동
  3. 기존 traslate계산 전에 transition을 all으로 변경하여 다시 슬라이더가 자연스럽게 이동할 수 있도록 처리

useInterval 추가

setInterval을 컴포넌트 내부에서 멈췄다 다시 진행시켰다 하는 부분이 내부 렌더링 로직에 의해 의도대로 동작하지 않는 문제를 해결하기 위한 훅인 useInterval 기능을 추가하였습니다.

@d0422 d0422 added the enhancement New feature or request label May 10, 2024
@d0422 d0422 requested a review from HBSPS May 10, 2024 04:11
@d0422 d0422 self-assigned this May 10, 2024
@d0422 d0422 added the feature label May 10, 2024
Copy link
Contributor

@HBSPS HBSPS left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

수고하셨습니다!

Comment on lines 81 to 84
ref.current!.style.transition = 'none';
ref.current!.style.transform = `translateX(${-getSliderWidth()}px)`;
setIndex(1);
ref.current!.removeEventListener('transitionend', resetToFirstPage);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ref.current가 있는지 이미 검사하고 있기 때문에 assertion을 사용하지 않아도 될 것 같아요!

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

반영하였습니다!

@@ -133,7 +183,7 @@ export default function useDragIndexCarousel(
prev,
isEnd,
isStart,
} = _useDragIndexCarousel(dataLength - 1, minMove, startIndex);
} = _useDragIndexCarousel(realDataLength, minMove, startIndex, infinity);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

_useDragIndexCarousel를 사용했다면 handleTouchStart과 같은 이벤트 핸들러들의 타입 추론이 되지 않나요??

190번째 줄부터 as any가 꼭 필요할까요?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

이벤트 타입 때문에 이런 문제가 발생했네요!
React.TouchEvent가 아니라 TouchEvent로 변경하여 any제거하였습니다!

Comment on lines 8 to 9
} from 'react';
import { useRef, useState, Children, ReactNode } from 'react';
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

react가 중복 import 되어있네요

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

반영하였습니다!

@d0422 d0422 merged commit 253c067 into Rapiders:main May 10, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request feature
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants