Skip to content

[URH-49] useScrollLock 신규 #44

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

Merged
merged 5 commits into from
Aug 16, 2024
Merged

[URH-49] useScrollLock 신규 #44

merged 5 commits into from
Aug 16, 2024

Conversation

foresec
Copy link
Collaborator

@foresec foresec commented Aug 9, 2024

👾 Pull Request

  • 상태: 신규

1️⃣ Spec

  • 페이지의 스크롤을 잠그거나 해제하여 사용자가 스크롤할 수 없도록 하는 훅
  • scroll바가 존재하여 UI형태는 유지되지만 비활성화된 형태

2️⃣ 변경 사항

  • 없음

3️⃣ 예시 코드

  • boolean 값으로 scrollLock 여부를 처리합니다
const App = () => {
  const [isModalOpen, setIsModalOpen] = useState<boolean>(false);

  useScrollLock(isModalOpen);

  const openModal = () => {
    setIsModalOpen(true);
  };

  const closeModal = () => {
    setIsModalOpen(false);
  };

  return (
    <div style={styles.container}>
      {isModalOpen && (
        <div style={styles.modal}>
          <div style={styles.modalContent}>
     ...
    </div>
  );
};

위 예시처럼 isOpen과 같이 modal이 열리고 닫히는 경우 등에 해당 boolean값을 넣으면 scollLock 처리가 됨

ddd.mp4

4️⃣ 관련 문서 (선택 사항)

✨ feat: 페이지를 고정하고 스크롤을 저장하는 형태의 scrollLock구현

✅ test: useScrollLock 테스트 코드 추가

✨ feat: window 관련 client환경 구분 추가

📝 docs: useScrollLock jsdocs 작성

🐛 fix: 테스트코드 window관련 mock 수정
@Choozii Choozii requested review from bicochan and Choozii August 9, 2024 10:20
@foresec foresec changed the title [URH-39] useScrollLock 신규 [URH-49] useScrollLock 신규 Aug 9, 2024
Copy link
Member

@Choozii Choozii left a comment

Choose a reason for hiding this comment

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

[P3]

if (isLocked) {
      lockScroll();
    } else {
      unlockScroll();
    }

    return () => {
      unlockScroll();
    };   

메인 로직이 쉽게 읽힐 수 있도록 로직을 함수로 묶어보는건 어떠세요?
saveScrollPosition, restoreScrollPosition, lockScroll....
이런식으로 정의해두고 호출하는 방식으로 하면 가독성이 더 좋아질거 같아요!

Copy link
Member

@bicochan bicochan left a comment

Choose a reason for hiding this comment

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

고생하셨어요 소현 님!👏🏻👏🏻

추후에 스크롤을 고정시킬 요소들을 스택 형식으로 받아서 중복 레이어들에 대한 처리도 해보면 더 멋진 훅이 될 것 같네요 ㅎㅎ

@foresec
Copy link
Collaborator Author

foresec commented Aug 12, 2024

추후에 스크롤을 고정시킬 요소들을 스택 형식으로 받아서 중복 레이어들에 대한 처리도 해보면 더 멋진 훅이 될 것 같네요 ㅎㅎ

@bicochan 서비스 화면상에서 중복레이어를 받는 처리를 적용할 수 있는 실제 사례를 혹시 알수 있을까요? 당장 떠오르지가 않아 질문드립니다. 그리고 혹 해당 기능을 추가한 훅을 만든다면 이 훅안에 추가하는게 나을지 아니면 useScrollMultiLock과 같이 분리하는게 나을지 고민됩니다

@foresec foresec closed this Aug 12, 2024
@foresec
Copy link
Collaborator Author

foresec commented Aug 12, 2024

[P3]

if (isLocked) {
      lockScroll();
    } else {
      unlockScroll();
    }

    return () => {
      unlockScroll();
    };   

메인 로직이 쉽게 읽힐 수 있도록 로직을 함수로 묶어보는건 어떠세요? saveScrollPosition, restoreScrollPosition, lockScroll.... 이런식으로 정의해두고 호출하는 방식으로 하면 가독성이 더 좋아질거 같아요!

@Choozii a866cf4 해당 커밋에서 반영했습니다.
단.. 분리하는 김에 단일 책임의 원칙을 좀 강하게 적용했는데 이게 더 괜찮은 선택일지 모르겠네요

@foresec foresec reopened this Aug 12, 2024
Copy link
Member

@Choozii Choozii left a comment

Choose a reason for hiding this comment

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

수고하셨어용 ✨

@foresec foresec merged commit 86c356e into master Aug 16, 2024
3 checks passed
@foresec foresec deleted the URH-49/use-scroll-lock branch August 16, 2024 06:12
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants