From 3e9e64340ef39430ef4e66a251eb5d85a7edbc1e Mon Sep 17 00:00:00 2001 From: pwespi Date: Wed, 5 Feb 2020 13:01:04 +0100 Subject: [PATCH] fix(toast): unify duration across platforms (#2340) --- .../src/main/java/com/getcapacitor/plugin/Toast.java | 2 +- core/src/core-plugin-definitions.ts | 3 +++ core/src/web/toast.ts | 4 ++-- ios/Capacitor/Capacitor/Plugins/Toast.swift | 4 ++-- 4 files changed, 8 insertions(+), 5 deletions(-) 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 9450d837d7..5e3de683fe 100644 --- a/android/capacitor/src/main/java/com/getcapacitor/plugin/Toast.java +++ b/android/capacitor/src/main/java/com/getcapacitor/plugin/Toast.java @@ -20,7 +20,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)) { diff --git a/core/src/core-plugin-definitions.ts b/core/src/core-plugin-definitions.ts index 6107ac14df..f2e13d6d65 100644 --- a/core/src/core-plugin-definitions.ts +++ b/core/src/core-plugin-definitions.ts @@ -1652,6 +1652,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'; position?: 'top' | 'center' | 'bottom'; } diff --git a/core/src/web/toast.ts b/core/src/web/toast.ts index af2eb5e3ea..afb686461e 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 407355b3cb..ce0f0c58be 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 durationType = call.get("duration", String.self, "short")! + let duration = durationType == "long" ? 3500 : 2000 let position = call.get("position", String.self, "bottom") DispatchQueue.main.async {