-
Notifications
You must be signed in to change notification settings - Fork 1.4k
Add support for long press to MenuTrigger #780 #789
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
Closed
intergalacticspacehighway
wants to merge
18
commits into
adobe:main
from
intergalacticspacehighway:780-longpress-menuTrigger
Closed
Changes from all commits
Commits
Show all changes
18 commits
Select commit
Hold shift + click to select a range
1180de2
Add support for long press to MenuTrigger #780
c9ce0aa
Add support for long press to MenuTrigger #780 | Cleanup and Storyboo…
50b4938
use mergeProps - MenuTrigger longPress #780
8af1223
Remove unnecessary condition from useLongPress - MenuTrigger longPres…
665deec
Remove unnecessary prop definitions from useLongPress - MenuTrigger l…
437b01f
Updated testcases- MenuTrigger longPress #780
8a3516f
Updated documentation - MenuTrigger longPress #780
0e7fb6d
Copyright text in useLongPress - MenuTrigger longPress #780
a8d1db1
Lint fixes - #780
d531280
MenuTrigger longPress #780 - only mouse or touch events and update te…
08c165c
MenuTrigger longPress #780 - Merge conflicts resolved and fixed faili…
c8046ea
MenuTrigger longPress #780 - Merge conflicts resolved with main
9580958
780-longpress | merge conflicts resolved
9af5afc
780-longpress | Lint issues fix
94ad476
Merge branch 'main' into 780-longpress-menuTrigger
24bb97f
Fix lint error
43f1c0b
Fix lint error
f078f9f
780-longpress-menuTrigger | Fix lint errors
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 hidden or 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 hidden or 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 |
|---|---|---|
| @@ -0,0 +1,57 @@ | ||
| /* | ||
| * Copyright 2020 Adobe. All rights reserved. | ||
| * This file is licensed to you under the Apache License, Version 2.0 (the "License"); | ||
| * you may not use this file except in compliance with the License. You may obtain a copy | ||
| * of the License at http://www.apache.org/licenses/LICENSE-2.0 | ||
| * | ||
| * Unless required by applicable law or agreed to in writing, software distributed under | ||
| * the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS | ||
| * OF ANY KIND, either express or implied. See the License for the specific language | ||
| * governing permissions and limitations under the License. | ||
| */ | ||
|
|
||
| import {PressEvent} from '@react-types/shared'; | ||
| import {usePress} from './usePress'; | ||
| import {useRef} from 'react'; | ||
|
|
||
| export interface LongPressHookProps { | ||
| onLongPress: (e: PressEvent) => void, | ||
| onPressStart?: (e: PressEvent) => void, | ||
| triggerThreshold?: number | ||
| } | ||
|
|
||
| export const LONG_PRESS_DEFAULT_THRESHOLD_IN_MS = 500; | ||
|
|
||
| export function useLongPress(props : LongPressHookProps) { | ||
| let { | ||
| onPressStart, | ||
| onLongPress, | ||
| triggerThreshold | ||
| } = props; | ||
|
|
||
| triggerThreshold = triggerThreshold || LONG_PRESS_DEFAULT_THRESHOLD_IN_MS; | ||
|
|
||
| const timeRef = useRef(null); | ||
|
|
||
| let {pressProps} = usePress({ | ||
| onPressStart(e) { | ||
| if (e.pointerType === 'mouse' || e.pointerType === 'touch') { | ||
| if (onPressStart) { | ||
| onPressStart(e); | ||
| } | ||
|
|
||
| timeRef.current = setTimeout(() => { | ||
| onLongPress(e); | ||
| timeRef.current = null; | ||
| }, triggerThreshold); | ||
| } | ||
| }, | ||
| onPressEnd() { | ||
| if (timeRef.current) { | ||
| clearTimeout(timeRef.current); | ||
| } | ||
| } | ||
| }); | ||
|
|
||
| return pressProps; | ||
| } |
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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
Oops, something went wrong.
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.
Uh oh!
There was an error while loading. Please reload this page.
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.
Recent changes for fixing #925 updated the behaviour of useOverlay. Earlier, onBlurWithin used to get called which calls onClose but now the toggle is only handled by onPressStart from pressProps. (For trigger buttons)
To replicate a similar behavior, I added state.close here. Let me know if it can be done in a better way.