Skip to content

Commit

Permalink
fix(toast): unify duration across platforms (#2340)
Browse files Browse the repository at this point in the history
  • Loading branch information
pwespi committed Feb 5, 2020
1 parent a0bcf5c commit 717dd0a
Show file tree
Hide file tree
Showing 4 changed files with 8 additions and 5 deletions.
Expand Up @@ -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)) {
Expand Down
3 changes: 3 additions & 0 deletions core/src/core-plugin-definitions.ts
Expand Up @@ -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';
}
Expand Down
4 changes: 2 additions & 2 deletions core/src/web/toast.ts
Expand Up @@ -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;
Expand Down
4 changes: 2 additions & 2 deletions ios/Capacitor/Capacitor/Plugins/Toast.swift
Expand Up @@ -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 {
Expand Down

0 comments on commit 717dd0a

Please sign in to comment.