From 14f286c47f1d408d24c45fc49135b1d4bce6d852 Mon Sep 17 00:00:00 2001 From: Sean Bannigan Date: Sun, 5 Apr 2020 16:38:58 -0400 Subject: [PATCH] feat(android/haptics): implement selection haptic feedback --- .../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 3b7394e084..798f597c92 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 b3fd0b3115..fe7217ca7c 100644 --- a/core/src/core-plugin-definitions.ts +++ b/core/src/core-plugin-definitions.ts @@ -921,7 +921,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 3bd2a2a4d1..428e60d1d1 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