From 8e11ecc136c61e925e76c0e48ab21611e09b5898 Mon Sep 17 00:00:00 2001 From: Liam DeBeasi Date: Mon, 11 May 2020 15:10:19 -0400 Subject: [PATCH] fix(picker): haptics now work properly (#21268) --- .../picker-column/picker-column.tsx | 5 +- .../reorder-group/reorder-group.tsx | 2 +- core/src/components/toggle/toggle.tsx | 2 +- core/src/utils/haptic.ts | 72 ------------------- 4 files changed, 6 insertions(+), 75 deletions(-) delete mode 100644 core/src/utils/haptic.ts diff --git a/core/src/components/picker-column/picker-column.tsx b/core/src/components/picker-column/picker-column.tsx index 5372a2e9c7..f884d4205e 100644 --- a/core/src/components/picker-column/picker-column.tsx +++ b/core/src/components/picker-column/picker-column.tsx @@ -2,8 +2,8 @@ import { Component, ComponentInterface, Element, Event, EventEmitter, Host, Prop import { getIonMode } from '../../global/ionic-global'; import { Gesture, GestureDetail, PickerColumn } from '../../interface'; -import { hapticSelectionChanged } from '../../utils/haptic'; import { clamp } from '../../utils/helpers'; +import { hapticSelectionChanged, hapticSelectionEnd, hapticSelectionStart } from '../../utils/native/haptic'; /** * @internal @@ -226,6 +226,7 @@ export class PickerColumnCmp implements ComponentInterface { } else { this.velocity = 0; this.emitColChange(); + hapticSelectionEnd(); } } else if (this.y % this.optHeight !== 0) { @@ -252,6 +253,8 @@ export class PickerColumnCmp implements ComponentInterface { detail.event.preventDefault(); detail.event.stopPropagation(); + hapticSelectionStart(); + // reset everything cancelAnimationFrame(this.rafId); const options = this.col.options; diff --git a/core/src/components/reorder-group/reorder-group.tsx b/core/src/components/reorder-group/reorder-group.tsx index d2b449c3a1..b49aa48648 100644 --- a/core/src/components/reorder-group/reorder-group.tsx +++ b/core/src/components/reorder-group/reorder-group.tsx @@ -2,7 +2,7 @@ import { Component, ComponentInterface, Element, Event, EventEmitter, Host, Meth import { getIonMode } from '../../global/ionic-global'; import { Gesture, GestureDetail, ItemReorderEventDetail } from '../../interface'; -import { hapticSelectionChanged, hapticSelectionEnd, hapticSelectionStart } from '../../utils/haptic'; +import { hapticSelectionChanged, hapticSelectionEnd, hapticSelectionStart } from '../../utils/native/haptic'; const enum ReorderGroupState { Idle = 0, diff --git a/core/src/components/toggle/toggle.tsx b/core/src/components/toggle/toggle.tsx index e5df21dae7..4ae16bd4d8 100644 --- a/core/src/components/toggle/toggle.tsx +++ b/core/src/components/toggle/toggle.tsx @@ -2,8 +2,8 @@ import { Component, ComponentInterface, Element, Event, EventEmitter, Host, Prop import { getIonMode } from '../../global/ionic-global'; import { Color, Gesture, GestureDetail, StyleEventDetail, ToggleChangeEventDetail } from '../../interface'; -import { hapticSelection } from '../../utils/haptic'; import { findItemLabel, renderHiddenInput } from '../../utils/helpers'; +import { hapticSelection } from '../../utils/native/haptic'; import { createColorClasses, hostContext } from '../../utils/theme'; /** diff --git a/core/src/utils/haptic.ts b/core/src/utils/haptic.ts deleted file mode 100644 index a164724cab..0000000000 --- a/core/src/utils/haptic.ts +++ /dev/null @@ -1,72 +0,0 @@ -/** - * Check to see if the Haptic Plugin is available - * @return Returns `true` or false if the plugin is available - */ -export const hapticAvailable = (): boolean => { - const engine = (window as any).TapticEngine; - return !!engine; -}; - -/** - * Trigger a selection changed haptic event. Good for one-time events - * (not for gestures) - */ -export const hapticSelection = () => { - const engine = (window as any).TapticEngine; - if (engine) { - engine.selection(); - } -}; - -/** - * Tell the haptic engine that a gesture for a selection change is starting. - */ -export const hapticSelectionStart = () => { - const engine = (window as any).TapticEngine; - if (engine) { - engine.gestureSelectionStart(); - } -}; - -/** - * Tell the haptic engine that a selection changed during a gesture. - */ -export const hapticSelectionChanged = () => { - const engine = (window as any).TapticEngine; - if (engine) { - engine.gestureSelectionChanged(); - } -}; - -/** - * Tell the haptic engine we are done with a gesture. This needs to be - * called lest resources are not properly recycled. - */ -export const hapticSelectionEnd = () => { - const engine = (window as any).TapticEngine; - if (engine) { - engine.gestureSelectionEnd(); - } -}; - -/** - * Use this to indicate success/failure/warning to the user. - * options should be of the type `{ type: 'success' }` (or `warning`/`error`) - */ -export const hapticNotification = (options: { type: 'success' | 'warning' | 'error' }) => { - const engine = (window as any).TapticEngine; - if (engine) { - engine.notification(options); - } -}; - -/** - * Use this to indicate success/failure/warning to the user. - * options should be of the type `{ style: 'light' }` (or `medium`/`heavy`) - */ -export const hapticImpact = (options: { style: 'light' | 'medium' | 'heavy' }) => { - const engine = (window as any).TapticEngine; - if (engine) { - engine.impact(options); - } -};