diff --git a/android/capacitor/src/main/java/com/getcapacitor/Bridge.java b/android/capacitor/src/main/java/com/getcapacitor/Bridge.java index 381d31e6cd..002705d31c 100644 --- a/android/capacitor/src/main/java/com/getcapacitor/Bridge.java +++ b/android/capacitor/src/main/java/com/getcapacitor/Bridge.java @@ -23,7 +23,6 @@ import com.getcapacitor.plugin.Device; import com.getcapacitor.plugin.Filesystem; import com.getcapacitor.plugin.Geolocation; -import com.getcapacitor.plugin.Haptics; import com.getcapacitor.plugin.Keyboard; import com.getcapacitor.plugin.LocalNotifications; import com.getcapacitor.plugin.Modals; @@ -402,7 +401,6 @@ private void registerAllPlugins() { this.registerPlugin(LocalNotifications.class); this.registerPlugin(Filesystem.class); this.registerPlugin(Geolocation.class); - this.registerPlugin(Haptics.class); this.registerPlugin(Keyboard.class); this.registerPlugin(Modals.class); this.registerPlugin(Network.class); diff --git a/android/capacitor/src/main/java/com/getcapacitor/plugin/Haptics.java b/android/capacitor/src/main/java/com/getcapacitor/plugin/Haptics.java deleted file mode 100644 index a8eb9d9133..0000000000 --- a/android/capacitor/src/main/java/com/getcapacitor/plugin/Haptics.java +++ /dev/null @@ -1,77 +0,0 @@ -package com.getcapacitor.plugin; - -import android.Manifest; -import android.content.Context; -import android.os.Build; -import android.os.VibrationEffect; -import android.os.Vibrator; -import android.view.HapticFeedbackConstants; -import com.getcapacitor.NativePlugin; -import com.getcapacitor.Plugin; -import com.getcapacitor.PluginCall; -import com.getcapacitor.PluginMethod; - -/** - * Haptic engine plugin, also handles vibration. - * - * Requires the android.permission.VIBRATE permission. - */ -@NativePlugin -public class Haptics extends Plugin { - boolean selectionStarted = false; - - @PluginMethod - @SuppressWarnings("MissingPermission") - public void vibrate(PluginCall call) { - Context c = this.getContext(); - int duration = call.getInt("duration", 300); - - if (!hasPermission(Manifest.permission.VIBRATE)) { - call.error("Can't vibrate: Missing VIBRATE permission in AndroidManifest.xml"); - return; - } - - if (Build.VERSION.SDK_INT >= 26) { - ((Vibrator) c.getSystemService(Context.VIBRATOR_SERVICE)).vibrate( - VibrationEffect.createOneShot(duration, VibrationEffect.DEFAULT_AMPLITUDE) - ); - } else { - vibratePre26(duration); - } - - call.success(); - } - - @SuppressWarnings({ "deprecation", "MissingPermission" }) - private void vibratePre26(int duration) { - ((Vibrator) getContext().getSystemService(Context.VIBRATOR_SERVICE)).vibrate(duration); - } - - @PluginMethod - public void impact(PluginCall call) { - this.bridge.getWebView().performHapticFeedback(HapticFeedbackConstants.LONG_PRESS); - call.success(); - } - - @PluginMethod - public void notification(PluginCall call) { - call.unimplemented(); - } - - @PluginMethod - public void selectionStart(PluginCall call) { - this.selectionStarted = true; - } - - @PluginMethod - public void selectionChanged(PluginCall call) { - if (this.selectionStarted) { - this.bridge.getWebView().performHapticFeedback(HapticFeedbackConstants.CLOCK_TICK); - } - } - - @PluginMethod - public void selectionEnd(PluginCall call) { - this.selectionStarted = false; - } -} diff --git a/core/src/core-plugin-definitions.ts b/core/src/core-plugin-definitions.ts index 7630edb3a2..be34caec88 100644 --- a/core/src/core-plugin-definitions.ts +++ b/core/src/core-plugin-definitions.ts @@ -9,7 +9,6 @@ export interface PluginRegistry { Device: DevicePlugin; Filesystem: FilesystemPlugin; Geolocation: GeolocationPlugin; - Haptics: HapticsPlugin; Keyboard: KeyboardPlugin; LocalNotifications: LocalNotificationsPlugin; Modals: ModalsPlugin; @@ -928,62 +927,6 @@ export type GeolocationWatchCallback = ( // -export interface HapticsPlugin extends Plugin { - /** - * Trigger a haptics "impact" feedback - */ - impact(options: HapticsImpactOptions): void; - /** - * Trigger a haptics "notification" feedback - */ - notification(options: HapticsNotificationOptions): void; - /** - * Vibrate the device - */ - vibrate(): void; - /** - * Trigger a selection started haptic hint - */ - selectionStart(): void; - /** - * Trigger a selection changed haptic hint. If a selection was - * started already, this will cause the device to provide haptic - * feedback - */ - selectionChanged(): void; - /** - * If selectionStart() was called, selectionEnd() ends the selection. - * For example, call this when a user has lifted their finger from a control - */ - selectionEnd(): void; -} - -export interface HapticsImpactOptions { - style: HapticsImpactStyle; -} - -export enum HapticsImpactStyle { - Heavy = 'HEAVY', - Medium = 'MEDIUM', - Light = 'LIGHT', -} - -export interface HapticsNotificationOptions { - type: HapticsNotificationType; -} - -export enum HapticsNotificationType { - SUCCESS = 'SUCCESS', - WARNING = 'WARNING', - ERROR = 'ERROR', -} - -export interface VibrateOptions { - duration?: number; -} - -// - export interface KeyboardPlugin extends Plugin { /** * Show the keyboard. This method is alpha and may have issues diff --git a/ios/Capacitor/Capacitor/Plugins/DefaultPlugins.m b/ios/Capacitor/Capacitor/Plugins/DefaultPlugins.m index 13acbfd2d6..32bfbd0056 100644 --- a/ios/Capacitor/Capacitor/Plugins/DefaultPlugins.m +++ b/ios/Capacitor/Capacitor/Plugins/DefaultPlugins.m @@ -62,15 +62,6 @@ CAP_PLUGIN_METHOD(clearWatch, CAPPluginReturnPromise); ) -CAP_PLUGIN(CAPHapticsPlugin, "Haptics", - CAP_PLUGIN_METHOD(impact, CAPPluginReturnNone); - CAP_PLUGIN_METHOD(notification, CAPPluginReturnNone); - CAP_PLUGIN_METHOD(selectionStart, CAPPluginReturnNone); - CAP_PLUGIN_METHOD(selectionChanged, CAPPluginReturnNone); - CAP_PLUGIN_METHOD(selectionEnd, CAPPluginReturnNone); - CAP_PLUGIN_METHOD(vibrate, CAPPluginReturnNone); -) - CAP_PLUGIN(CAPKeyboard, "Keyboard", CAP_PLUGIN_METHOD(show, CAPPluginReturnPromise); CAP_PLUGIN_METHOD(hide, CAPPluginReturnPromise); diff --git a/ios/Capacitor/Capacitor/Plugins/Haptics.swift b/ios/Capacitor/Capacitor/Plugins/Haptics.swift deleted file mode 100644 index 100ea3a46a..0000000000 --- a/ios/Capacitor/Capacitor/Plugins/Haptics.swift +++ /dev/null @@ -1,71 +0,0 @@ -import Foundation -import AudioToolbox - -@objc(CAPHapticsPlugin) -public class CAPHapticsPlugin: CAPPlugin { - var selectionFeedbackGenerator: UISelectionFeedbackGenerator? - - @objc public func impact(_ call: CAPPluginCall) { - DispatchQueue.main.async { - if let style = call.options["style"] as? String { - var impactStyle = UIImpactFeedbackGenerator.FeedbackStyle.heavy - if style == "MEDIUM" { - impactStyle = UIImpactFeedbackGenerator.FeedbackStyle.medium - } else if style == "LIGHT" { - impactStyle = UIImpactFeedbackGenerator.FeedbackStyle.light - } - - let generator = UIImpactFeedbackGenerator(style: impactStyle) - generator.impactOccurred() - } else { - let generator = UIImpactFeedbackGenerator(style: .heavy) - generator.impactOccurred() - } - } - } - - @objc public func notification(_ call: CAPPluginCall) { - DispatchQueue.main.async { - let generator = UINotificationFeedbackGenerator() - if let type = call.options["type"] as? String { - var notificationType = UINotificationFeedbackGenerator.FeedbackType.success - if type == "WARNING" { - notificationType = UINotificationFeedbackGenerator.FeedbackType.warning - } else if type == "ERROR" { - notificationType = UINotificationFeedbackGenerator.FeedbackType.error - } - generator.notificationOccurred(notificationType) - } else { - generator.notificationOccurred(.success) - } - } - } - - @objc public func selectionStart(_ call: CAPPluginCall) { - DispatchQueue.main.async { - self.selectionFeedbackGenerator = UISelectionFeedbackGenerator() - self.selectionFeedbackGenerator?.prepare() - } - } - - @objc public func selectionChanged(_ call: CAPPluginCall) { - DispatchQueue.main.async { - if let generator = self.selectionFeedbackGenerator { - generator.selectionChanged() - generator.prepare() - } - } - } - - @objc public func selectionEnd(_ call: CAPPluginCall) { - DispatchQueue.main.async { - self.selectionFeedbackGenerator = nil - } - } - - @objc public func vibrate(_ call: CAPPluginCall) { - DispatchQueue.main.async { - AudioServicesPlayAlertSound(kSystemSoundID_Vibrate) - } - } -}