-
Notifications
You must be signed in to change notification settings - Fork 3
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/#333 refactor custom hook #334
Open
ilmerry
wants to merge
17
commits into
release/2.1.1
Choose a base branch
from
feat/#333
base: release/2.1.1
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 1 commit
Commits
Show all changes
17 commits
Select commit
Hold shift + click to select a range
05c5b0d
[ refactor ] useShowByQuery to useCardType
ilmerry 300f4cb
[ etc ] remove useShowByQuery
ilmerry 2beb678
[ etc ] move useRecentlyBookmarked and useCardsByGender
ilmerry fb6e963
[ refactor ] useDraggableYContainer to useDraggingContainer
ilmerry 903cc2d
[ fix ] mobile undragging error
ilmerry 6a60f14
[ refactor ] eventHandler using SyntheicEvent
ilmerry 8cce380
[ fix ] unDragging problem caused by gradient
ilmerry 4b16682
[ refactor ] rename handlers
ilmerry 5ff0135
[ refactor ] add event mapper
ilmerry c1b1a1c
[ refactor ] add getPageByEventType
ilmerry a5e073f
[ fix ] active gradient
ilmerry a2e5c18
[ etc ] remove useDraggableYContainer
ilmerry 6c7b179
[ refactor ] useDrawer
ilmerry 15bf514
[ refactor ] page, client 통일
ilmerry 54bf17c
[ refactor ] 중복타이핑 제거 및 변수명 변경
ilmerry 902fc59
[ refactor ] MouseHandler와 TouchHandler 분리하기
ilmerry 16547fb
[ refactor ] handler 함수명 재변경
ilmerry File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,40 +1,47 @@ | ||
import { useRef, useState } from "react"; | ||
|
||
export default function useDraggingContainer() { | ||
type DragDirectionType = "X" | "Y"; | ||
|
||
export default function useDraggingContainer(dragDirection: DragDirectionType) { | ||
const containerRef = useRef<HTMLElement | null>(null); | ||
|
||
const [isStartDragging, setIsStartDragging] = useState(false); | ||
const currentX = useRef(0); | ||
const currentRef = useRef(0); | ||
|
||
const standardX = useRef(0); | ||
const [draggedX, setDraggedX] = useState(0); | ||
const standardRef = useRef(0); | ||
const [dragged, setDragged] = useState(0); | ||
|
||
function handleMouseDown(event: React.MouseEvent<HTMLElement, MouseEvent>) { | ||
setIsStartDragging(true); | ||
|
||
currentX.current = event.pageX; | ||
const page = dragDirection === "X" ? event.pageX : event.pageY; | ||
currentRef.current = page; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 👍🏼👍🏼 |
||
|
||
initializeForDraggedX(event.pageX); | ||
initializeForDragged(page); | ||
} | ||
|
||
function initializeForDraggedX(standartX: number) { | ||
setDraggedX(0); | ||
standardX.current = standartX; | ||
function initializeForDragged(standard: number) { | ||
setDragged(0); | ||
standardRef.current = standard; | ||
} | ||
|
||
function handleMouseMove(event: React.MouseEvent<HTMLElement, MouseEvent>) { | ||
const container = containerRef.current; | ||
if (!container) return; | ||
if (!isStartDragging) return; | ||
|
||
moveContainerByCurrentX(container, event.pageX); | ||
const page = dragDirection === "X" ? event.pageX : event.pageY; | ||
|
||
moveContainerByCurrent(container, page); | ||
|
||
setDraggedX(Math.abs(event.pageX - standardX.current)); | ||
setDragged(Math.abs(page - standardRef.current)); | ||
} | ||
|
||
function moveContainerByCurrentX(container: HTMLElement, movedMouseX: number) { | ||
container.scrollLeft += currentX.current - movedMouseX; | ||
currentX.current = movedMouseX; | ||
function moveContainerByCurrent(container: HTMLElement, movedMouseX: number) { | ||
dragDirection === "X" | ||
? (container.scrollLeft += currentRef.current - movedMouseX) | ||
: (container.scrollTop += currentRef.current - movedMouseX); | ||
currentRef.current = movedMouseX; | ||
} | ||
|
||
function handleMouseUpOrLeave() { | ||
|
@@ -43,8 +50,8 @@ export default function useDraggingContainer() { | |
|
||
function reset() { | ||
setIsStartDragging(false); | ||
currentX.current = 0; | ||
standardX.current = 0; | ||
currentRef.current = 0; | ||
standardRef.current = 0; | ||
} | ||
|
||
return { | ||
|
@@ -55,6 +62,6 @@ export default function useDraggingContainer() { | |
onMouseUp: handleMouseUpOrLeave, | ||
onMouseLeave: handleMouseUpOrLeave, | ||
}, | ||
isDragging: draggedX > 10, | ||
isDragging: dragged > 10, | ||
}; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
'horizon'도 아닌, 'x'도 아닌, 'X'인 이유가 있을까요?
추상화 레벨 적절하게 열어진 것 다 좋은데, 이 인자값 인터페이스가 조금 어색해보여요
타이핑도 되어있고 해서 지금 상태도 괜찮지만, 가능하다면 좀 더 일반적으로 기대 가능한 인터페이스면 어떨까 싶습니다!!!!!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
읽는 사람들(개발자들)에게
x/y
는 'x축', 'y축'이라는 통용된 개념으로 읽히기 때문에horizon/vertical
으로 굳이 길게 늘릴 필요가 없다고 생각했어요!x/y와 X/Y 중 고민했는데, 속성명 중에 pageX, pageY가 있기 때문에 통일성을 주기 위해 X, Y를 사용했습니다.
x/y가 좀 더 가독성이 낫다고 느끼신다면 고쳐보겠습니다!