From 9ff9ba06d74d5b960eab65353d20a2674baf506a Mon Sep 17 00:00:00 2001 From: pwespi Date: Wed, 15 Jan 2020 19:19:18 +0100 Subject: [PATCH 1/3] fix(toast): unify toast duration values and default across platforms --- core/src/core-plugin-definitions.ts | 3 +++ core/src/web/toast.ts | 4 ++-- ios/Capacitor/Capacitor/Plugins/Toast.swift | 4 ++-- 3 files changed, 7 insertions(+), 4 deletions(-) diff --git a/core/src/core-plugin-definitions.ts b/core/src/core-plugin-definitions.ts index e7644b5d4..36e062f49 100644 --- a/core/src/core-plugin-definitions.ts +++ b/core/src/core-plugin-definitions.ts @@ -1619,6 +1619,9 @@ export interface ToastPlugin extends Plugin { export interface ToastShowOptions { text: string; + /** + * Duration of the toast, either 'short' (2000ms, default) or 'long' (3500ms) + */ duration?: 'short' | 'long'; } diff --git a/core/src/web/toast.ts b/core/src/web/toast.ts index af2eb5e3e..afb686461 100644 --- a/core/src/web/toast.ts +++ b/core/src/web/toast.ts @@ -11,9 +11,9 @@ export class ToastPluginWeb extends WebPlugin implements ToastPlugin { } async show(options: ToastShowOptions) { - let duration = 3000; + let duration = 2000; if (options.duration) { - duration = options.duration === 'long' ? 5000 : 3000; + duration = options.duration === 'long' ? 3500 : 2000; } const toast = document.createElement('pwa-toast') as any; toast.duration = duration; diff --git a/ios/Capacitor/Capacitor/Plugins/Toast.swift b/ios/Capacitor/Capacitor/Plugins/Toast.swift index 07350f727..4605633e3 100644 --- a/ios/Capacitor/Capacitor/Plugins/Toast.swift +++ b/ios/Capacitor/Capacitor/Plugins/Toast.swift @@ -10,8 +10,8 @@ public class CAPToastPlugin : CAPPlugin { call.error("text must be provided and must be a string.") return } - let durationStyle = call.get("durationStyle", String.self, "long")! - let duration = durationStyle == "short" ? 1500 : 3000 + let durationStyle = call.get("durationStyle", String.self, "short")! + let duration = durationStyle == "long" ? 3500 : 2000 DispatchQueue.main.async { let vc = self.bridge!.viewController From 9aa25c01318d55e884ab0e9b1e1913b135adf008 Mon Sep 17 00:00:00 2001 From: pwespi Date: Wed, 15 Jan 2020 20:09:13 +0100 Subject: [PATCH 2/3] fix(toast): use correct duration option in android --- .../capacitor/src/main/java/com/getcapacitor/plugin/Toast.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/android/capacitor/src/main/java/com/getcapacitor/plugin/Toast.java b/android/capacitor/src/main/java/com/getcapacitor/plugin/Toast.java index a15e60aea..c9d51d2c6 100644 --- a/android/capacitor/src/main/java/com/getcapacitor/plugin/Toast.java +++ b/android/capacitor/src/main/java/com/getcapacitor/plugin/Toast.java @@ -16,7 +16,7 @@ public void show(PluginCall call) { return; } - String durationType = call.getString("durationType", "short"); + String durationType = call.getString("duration", "short"); int duration = android.widget.Toast.LENGTH_SHORT; if("long".equals(durationType)) { From 0b756bda772d54823b70b467fb5244c42f7940a6 Mon Sep 17 00:00:00 2001 From: pwespi Date: Wed, 15 Jan 2020 20:27:54 +0100 Subject: [PATCH 3/3] fix(toast): use correct duration option in ios --- ios/Capacitor/Capacitor/Plugins/Toast.swift | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/ios/Capacitor/Capacitor/Plugins/Toast.swift b/ios/Capacitor/Capacitor/Plugins/Toast.swift index 4605633e3..80245a9df 100644 --- a/ios/Capacitor/Capacitor/Plugins/Toast.swift +++ b/ios/Capacitor/Capacitor/Plugins/Toast.swift @@ -10,8 +10,8 @@ public class CAPToastPlugin : CAPPlugin { call.error("text must be provided and must be a string.") return } - let durationStyle = call.get("durationStyle", String.self, "short")! - let duration = durationStyle == "long" ? 3500 : 2000 + let durationType = call.get("duration", String.self, "short")! + let duration = durationType == "long" ? 3500 : 2000 DispatchQueue.main.async { let vc = self.bridge!.viewController