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

[FE] NumberKeyboardBottomSheet 영역에서 스크롤이 가능한 문제 #633

Merged
merged 1 commit into from
Sep 26, 2024

Conversation

Todari
Copy link
Contributor

@Todari Todari commented Sep 25, 2024

issue

구현 목적

2024-09-25.1.37.00.mov

NumberKeyboardBottomSheet가 올라온 경우 해당 영역을 드래그 해도 스크롤이 가능한 문제가 있습니다.
이 경우 사용자가 의도하지 않은 대로 동작할 수 있고, 안좋은 유저 경험의 원인이 될 수 있다고 생각합니다.

구현 사항

  useEffect(() => {
    const bottomSheet = bottomSheetRef.current;
    if (!bottomSheet) return;

    const preventScroll = (e: TouchEvent) => {
      if (bottomSheet.contains(e.target as Node)) {
        e.preventDefault();
      }
    };

    if (isOpened) {
      document.addEventListener('touchmove', preventScroll, {passive: false});
    }

    return () => {
      document.removeEventListener('touchmove', preventScroll);
    };
  }, [isOpened]);
  • bottomSheet 영역에 touchMove Event가 있다면, touchEvent를 prevent 하도록 하는 코드를 작성했습니다.
  • 따라서 BottomSheet 영역을 드래그해도 preventEvent로 인해 뒷 영역의 스크롤이 작동하지 않습니다.

@Todari Todari added 🖥️ FE Frontend 🔍 QC quality check labels Sep 25, 2024
@Todari Todari added this to the v2.0.0 milestone Sep 25, 2024
@Todari Todari self-assigned this Sep 25, 2024
Copy link

Copy link
Contributor

@jinhokim98 jinhokim98 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 +34 to +35
z-index: 20;
touch-action: none;
Copy link
Contributor

Choose a reason for hiding this comment

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

touch action을 막아주신 코드인거죠?

Copy link
Contributor Author

@Todari Todari Sep 26, 2024

Choose a reason for hiding this comment

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

맞숨당~

};

if (isOpened) {
document.addEventListener('touchmove', preventScroll, {passive: false});
Copy link
Contributor

Choose a reason for hiding this comment

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

passive false는 어떤 의미인가요?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

passive 리스너는 preventDefault를 호출하지 않는 역할을 합니다~
touchMove event는 기본적으로 passive event 인데,
우리는 preventDefault를 호출하기 때문에 passive:false 를 통해서 preventDefault를 사용한다고 알려줘야합니당~

Copy link
Contributor

@soi-ha soi-ha left a comment

Choose a reason for hiding this comment

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

굳굳쓰입니댜 ~!

@@ -26,6 +31,8 @@ const NumberKeyboardBottomSheet = ({isOpened, onClose, ...props}: Props) => {
gap: 1rem;
bottom: 0;
background-color: ${theme.colors.white};
z-index: 20;
Copy link
Contributor

Choose a reason for hiding this comment

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

나아..중에,, 제가 만들어 둔 z-index token을 사용해야 겠군여

const bottomSheet = bottomSheetRef.current;
if (!bottomSheet) return;

const preventScroll = (e: TouchEvent) => {
Copy link
Contributor

Choose a reason for hiding this comment

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

굳굳쓰 ~

Copy link
Contributor

@pakxe pakxe left a comment

Choose a reason for hiding this comment

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

멋집니다!! 이런 오류를 발견하다니......

};

if (isOpened) {
document.addEventListener('touchmove', preventScroll, {passive: false});
Copy link
Contributor

Choose a reason for hiding this comment

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

touchMove라는 이벤트가 있었구뇽..!! 덕분에 알게됐어요 😆👍

const useNumberKeyboardBottomSheet = ({isOpened}: Props) => {
const bottomSheetRef = useRef<HTMLDivElement>(null);

useEffect(() => {
Copy link
Contributor

Choose a reason for hiding this comment

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

이건 굳이 싶을 수도 있긴한데요.! usePreventTouchMove라는 유틸함수 또는 훅으로 분리해서 사용할 수도 있을 것 같아요! 😁

Copy link
Contributor Author

Choose a reason for hiding this comment

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

오 그것도 좋은 방법이라고 생각합니다. touch를 막는 부분이 또 필요하다면 분리해보도록 할게요!

@soi-ha soi-ha merged commit dff7f4f into fe-dev Sep 26, 2024
2 checks passed
@soi-ha soi-ha deleted the feature/#617 branch September 26, 2024 06:21
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
🖥️ FE Frontend 🔍 QC quality check
Projects
Status: ✅ Done
Development

Successfully merging this pull request may close these issues.

[FE] NumberKeyboardBottomSheet 영역에서 스크롤이 가능한 문제
4 participants