From 33be1f061ebbe27ee22e357c394f112af42ec360 Mon Sep 17 00:00:00 2001 From: Liam DeBeasi Date: Tue, 26 May 2020 11:33:51 -0400 Subject: [PATCH] fix(ios): add haptic drag gesture for action sheet and alert components (#21060) --- .../action-sheet/action-sheet.ios.scss | 2 + .../components/action-sheet/action-sheet.scss | 1 + .../components/action-sheet/action-sheet.tsx | 40 ++++++++++++- core/src/components/alert/alert.ios.scss | 4 ++ core/src/components/alert/alert.tsx | 29 +++++++++- core/src/utils/gesture/button-active.ts | 58 +++++++++++++++++++ core/src/utils/native/haptic.ts | 4 +- 7 files changed, 132 insertions(+), 6 deletions(-) create mode 100644 core/src/utils/gesture/button-active.ts diff --git a/core/src/components/action-sheet/action-sheet.ios.scss b/core/src/components/action-sheet/action-sheet.ios.scss index 6eb41fd99c2..126e346f8e6 100644 --- a/core/src/components/action-sheet/action-sheet.ios.scss +++ b/core/src/components/action-sheet/action-sheet.ios.scss @@ -134,6 +134,8 @@ @include margin-horizontal(null, $action-sheet-ios-button-icon-padding-right); font-size: $action-sheet-ios-button-icon-font-size; + + pointer-events: none; } .action-sheet-button:last-child { diff --git a/core/src/components/action-sheet/action-sheet.scss b/core/src/components/action-sheet/action-sheet.scss index 0242a63265c..a19e11be192 100644 --- a/core/src/components/action-sheet/action-sheet.scss +++ b/core/src/components/action-sheet/action-sheet.scss @@ -112,6 +112,7 @@ flex-shrink: 0; align-items: center; justify-content: center; + pointer-events: none; width: 100%; height: 100%; diff --git a/core/src/components/action-sheet/action-sheet.tsx b/core/src/components/action-sheet/action-sheet.tsx index f4ef97e49f9..6c2b132b944 100644 --- a/core/src/components/action-sheet/action-sheet.tsx +++ b/core/src/components/action-sheet/action-sheet.tsx @@ -1,7 +1,9 @@ -import { Component, ComponentInterface, Element, Event, EventEmitter, Host, Method, Prop, h } from '@stencil/core'; +import { Component, ComponentInterface, Element, Event, EventEmitter, Host, Method, Prop, h, readTask } from '@stencil/core'; import { getIonMode } from '../../global/ionic-global'; import { ActionSheetButton, AnimationBuilder, CssClassMap, OverlayEventDetail, OverlayInterface } from '../../interface'; +import { Gesture } from '../../utils/gesture'; +import { createButtonActiveGesture } from '../../utils/gesture/button-active'; import { BACKDROP, dismiss, eventMethod, isCancel, prepareOverlay, present, safeCall } from '../../utils/overlays'; import { getClassMap } from '../../utils/theme'; @@ -25,6 +27,9 @@ export class ActionSheet implements ComponentInterface, OverlayInterface { presented = false; animation?: any; + private wrapperEl?: HTMLElement; + private groupEl?: HTMLElement; + private gesture?: Gesture; @Element() el!: HTMLIonActionSheetElement; @@ -192,6 +197,35 @@ export class ActionSheet implements ComponentInterface, OverlayInterface { } } + componentDidUnload() { + if (this.gesture) { + this.gesture.destroy(); + this.gesture = undefined; + } + } + + componentDidLoad() { + /** + * Do not create gesture if: + * 1. A gesture already exists + * 2. App is running in MD mode + * 3. A wrapper ref does not exist + */ + const { groupEl, wrapperEl } = this; + if (this.gesture || getIonMode(this) === 'md' || !wrapperEl || !groupEl) { return; } + + readTask(() => { + const isScrollable = groupEl.scrollHeight > groupEl.clientHeight; + if (!isScrollable) { + this.gesture = createButtonActiveGesture( + wrapperEl, + (refEl: HTMLElement) => refEl.classList.contains('action-sheet-button') + ); + this.gesture.enable(true); + } + }); + } + render() { const mode = getIonMode(this); const allButtons = this.getButtons(); @@ -216,9 +250,9 @@ export class ActionSheet implements ComponentInterface, OverlayInterface { onIonBackdropTap={this.onBackdropTap} > -