-
Notifications
You must be signed in to change notification settings - Fork 13.5k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(ios): add haptic drag gesture for action sheet and alert componen…
…ts (#21060)
- Loading branch information
1 parent
e53f024
commit 33be1f0
Showing
7 changed files
with
132 additions
and
6 deletions.
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
import { writeTask } from '@stencil/core'; | ||
|
||
import { hapticSelectionChanged, hapticSelectionEnd, hapticSelectionStart } from '../native/haptic'; | ||
|
||
import { Gesture, createGesture } from './index'; | ||
|
||
export const createButtonActiveGesture = ( | ||
el: HTMLElement, | ||
isButton: (refEl: HTMLElement) => boolean | ||
): Gesture => { | ||
let touchedButton: HTMLElement | undefined; | ||
|
||
const activateButtonAtPoint = (x: number, y: number, hapticFeedbackFn: () => void) => { | ||
if (typeof (document as any) === 'undefined') { return; } | ||
const target = document.elementFromPoint(x, y) as HTMLElement | null; | ||
if (!target || !isButton(target)) { | ||
clearActiveButton(); | ||
return; | ||
} | ||
|
||
if (target !== touchedButton) { | ||
clearActiveButton(); | ||
setActiveButton(target, hapticFeedbackFn); | ||
} | ||
}; | ||
|
||
const setActiveButton = (button: HTMLElement, hapticFeedbackFn: () => void) => { | ||
touchedButton = button; | ||
const buttonToModify = touchedButton; | ||
writeTask(() => buttonToModify.classList.add('ion-activated')); | ||
hapticFeedbackFn(); | ||
}; | ||
|
||
const clearActiveButton = (dispatchClick = false) => { | ||
if (!touchedButton) { return; } | ||
|
||
const buttonToModify = touchedButton; | ||
writeTask(() => buttonToModify.classList.remove('ion-activated')); | ||
|
||
if (dispatchClick) { | ||
touchedButton.click(); | ||
} | ||
|
||
touchedButton = undefined; | ||
}; | ||
|
||
return createGesture({ | ||
el, | ||
gestureName: 'buttonActiveDrag', | ||
threshold: 0, | ||
onStart: ev => activateButtonAtPoint(ev.currentX, ev.currentY, hapticSelectionStart), | ||
onMove: ev => activateButtonAtPoint(ev.currentX, ev.currentY, hapticSelectionChanged), | ||
onEnd: () => { | ||
clearActiveButton(true); | ||
hapticSelectionEnd(); | ||
} | ||
}); | ||
}; |
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