-
Notifications
You must be signed in to change notification settings - Fork 1.2k
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
refactor: Remove custom hit testing in usePress #7427
Merged
Merged
Changes from 1 commit
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
8503b04
refactor: Remove custom hit testing in usePress
devongovett 37f75c0
Merge branch 'main' of github.com:adobe/react-spectrum into usepress-…
devongovett b776da9
Only allow dragging to select an item with mouse, not touch
devongovett 8bc9880
Don't close when dragging outside submenu
devongovett 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -433,7 +433,13 @@ export function usePress(props: PressHookProps): PressResult { | |
|
||
shouldStopPropagation = triggerPressStart(e, state.pointerType); | ||
|
||
addGlobalListener(getOwnerDocument(e.currentTarget), 'pointermove', onPointerMove, false); | ||
// Release pointer capture so that touch interactions can leave the original target. | ||
// This enables onPointerLeave and onPointerEnter to fire. | ||
let target = e.target as Element; | ||
if ('releasePointerCapture' in target) { | ||
target.releasePointerCapture(e.pointerId); | ||
} | ||
|
||
addGlobalListener(getOwnerDocument(e.currentTarget), 'pointerup', onPointerUp, false); | ||
addGlobalListener(getOwnerDocument(e.currentTarget), 'pointercancel', onPointerCancel, false); | ||
} | ||
|
@@ -467,27 +473,20 @@ export function usePress(props: PressHookProps): PressResult { | |
} | ||
|
||
// Only handle left clicks | ||
// Safari on iOS sometimes fires pointerup events, even | ||
// when the touch isn't over the target, so double check. | ||
if (e.button === 0 && isOverTarget(e, e.currentTarget)) { | ||
if (e.button === 0) { | ||
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. I am not certain yet if this bug still exists in Safari. This was added in #335. Will need to test. |
||
triggerPressUp(e, state.pointerType || e.pointerType); | ||
} | ||
}; | ||
|
||
// Safari on iOS < 13.2 does not implement pointerenter/pointerleave events correctly. | ||
// Use pointer move events instead to implement our own hit testing. | ||
// See https://bugs.webkit.org/show_bug.cgi?id=199803 | ||
let onPointerMove = (e: PointerEvent) => { | ||
if (e.pointerId !== state.activePointerId) { | ||
return; | ||
pressProps.onPointerEnter = (e) => { | ||
if (e.pointerId === state.activePointerId && state.target && !state.isOverTarget && state.pointerType != null) { | ||
state.isOverTarget = true; | ||
triggerPressStart(createEvent(state.target, e), state.pointerType); | ||
} | ||
}; | ||
|
||
if (state.target && isOverTarget(e, state.target)) { | ||
if (!state.isOverTarget && state.pointerType != null) { | ||
state.isOverTarget = true; | ||
triggerPressStart(createEvent(state.target, e), state.pointerType); | ||
} | ||
} else if (state.target && state.isOverTarget && state.pointerType != null) { | ||
pressProps.onPointerLeave = (e) => { | ||
if (e.pointerId === state.activePointerId && state.target && state.isOverTarget && state.pointerType != null) { | ||
state.isOverTarget = false; | ||
triggerPressEnd(createEvent(state.target, e), state.pointerType, false); | ||
cancelOnPointerExit(e); | ||
|
@@ -496,7 +495,7 @@ export function usePress(props: PressHookProps): PressResult { | |
|
||
let onPointerUp = (e: PointerEvent) => { | ||
if (e.pointerId === state.activePointerId && state.isPressed && e.button === 0 && state.target) { | ||
if (isOverTarget(e, state.target) && state.pointerType != null) { | ||
if (state.target.contains(e.target as Element) && state.pointerType != null) { | ||
triggerPressEnd(createEvent(state.target, e), state.pointerType); | ||
} else if (state.isOverTarget && state.pointerType != null) { | ||
triggerPressEnd(createEvent(state.target, e), state.pointerType, false); | ||
|
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.
not supported in jsdom