From 34dd28052b3ab71ed6e88b12e4dc60c73c67c8a7 Mon Sep 17 00:00:00 2001 From: Sean Bannigan Date: Fri, 1 May 2020 12:42:26 -0400 Subject: [PATCH] feat(android): implement selection haptic feedback (#2704) --- .../src/main/java/com/getcapacitor/plugin/Haptics.java | 10 +++++++--- core/src/core-plugin-definitions.ts | 2 +- site/src/assets/docs-content/apis/haptics/api.html | 2 +- 3 files changed, 9 insertions(+), 5 deletions(-) diff --git a/android/capacitor/src/main/java/com/getcapacitor/plugin/Haptics.java b/android/capacitor/src/main/java/com/getcapacitor/plugin/Haptics.java index 3b7394e08..798f597c9 100644 --- a/android/capacitor/src/main/java/com/getcapacitor/plugin/Haptics.java +++ b/android/capacitor/src/main/java/com/getcapacitor/plugin/Haptics.java @@ -20,6 +20,8 @@ @NativePlugin() public class Haptics extends Plugin { + boolean selectionStarted = false; + @PluginMethod() @SuppressWarnings("MissingPermission") public void vibrate(PluginCall call) { @@ -58,16 +60,18 @@ public void notification(PluginCall call) { @PluginMethod() public void selectionStart(PluginCall call) { - call.unimplemented(); + this.selectionStarted = true; } @PluginMethod() public void selectionChanged(PluginCall call) { - call.unimplemented(); + if (this.selectionStarted) { + this.bridge.getWebView().performHapticFeedback(HapticFeedbackConstants.CLOCK_TICK); + } } @PluginMethod() public void selectionEnd(PluginCall call) { - call.unimplemented(); + this.selectionStarted = false; } } diff --git a/core/src/core-plugin-definitions.ts b/core/src/core-plugin-definitions.ts index 1b218f6b7..ff12893ea 100644 --- a/core/src/core-plugin-definitions.ts +++ b/core/src/core-plugin-definitions.ts @@ -934,7 +934,7 @@ export interface HapticsPlugin extends Plugin { /** * Trigger a selection changed haptic hint. If a selection was * started already, this will cause the device to provide haptic - * feedback (on iOS at least) + * feedback */ selectionChanged(): void; /** diff --git a/site/src/assets/docs-content/apis/haptics/api.html b/site/src/assets/docs-content/apis/haptics/api.html index 3bd2a2a4d..428e60d1d 100644 --- a/site/src/assets/docs-content/apis/haptics/api.html +++ b/site/src/assets/docs-content/apis/haptics/api.html @@ -44,7 +44,7 @@

selectionChang
Trigger a selection changed haptic hint. If a selection was started already, this will cause the device to provide haptic -feedback (on iOS at least)
+feedback