Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(toast): unify duration across platforms #2340

Merged
merged 4 commits into from
Feb 5, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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