fix(ios): add haptic drag gesture for action sheet and alert components (#21060)

This commit is contained in:
Liam DeBeasi
2020-05-26 11:33:51 -04:00
committed by GitHub
parent e53f0241e2
commit 33be1f061e
7 changed files with 132 additions and 6 deletions

View File

@@ -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();
}
});
};

View File

@@ -69,9 +69,9 @@ const HapticEngine = {
return;
}
if (this.isCapacitor()) {
engine.selectionChanged();
engine.selectionEnd();
} else {
engine.gestureSelectionChanged();
engine.gestureSelectionEnd();
}
}
};