From e3a38d77f738813432de80d5b1ac942b0469e4f5 Mon Sep 17 00:00:00 2001 From: jcesarmobile Date: Thu, 30 Jul 2020 17:26:09 +0200 Subject: [PATCH] chore: Remove haptics plugin --- .../main/java/com/getcapacitor/Bridge.java | 2 - .../java/com/getcapacitor/plugin/Haptics.java | 77 ------------------- core/src/core-plugin-definitions.ts | 57 -------------- .../Capacitor/Plugins/DefaultPlugins.m | 9 --- ios/Capacitor/Capacitor/Plugins/Haptics.swift | 71 ----------------- 5 files changed, 216 deletions(-) delete mode 100644 android/capacitor/src/main/java/com/getcapacitor/plugin/Haptics.java delete mode 100644 ios/Capacitor/Capacitor/Plugins/Haptics.swift diff --git a/android/capacitor/src/main/java/com/getcapacitor/Bridge.java b/android/capacitor/src/main/java/com/getcapacitor/Bridge.java index 6463786a42..70d68d147a 100644 --- a/android/capacitor/src/main/java/com/getcapacitor/Bridge.java +++ b/android/capacitor/src/main/java/com/getcapacitor/Bridge.java @@ -24,7 +24,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; @@ -406,7 +405,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 a4c89d42a5..684c9be7f2 100644 --- a/core/src/core-plugin-definitions.ts +++ b/core/src/core-plugin-definitions.ts @@ -10,7 +10,6 @@ export interface PluginRegistry { Device: DevicePlugin; Filesystem: FilesystemPlugin; Geolocation: GeolocationPlugin; - Haptics: HapticsPlugin; Keyboard: KeyboardPlugin; LocalNotifications: LocalNotificationsPlugin; Modals: ModalsPlugin; @@ -967,62 +966,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 b6d36d6f8e..c124197433 100644 --- a/ios/Capacitor/Capacitor/Plugins/DefaultPlugins.m +++ b/ios/Capacitor/Capacitor/Plugins/DefaultPlugins.m @@ -68,15 +68,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 6f5d90f03e..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) - } - } -}