ionic-team / ionic-framework

A powerful cross-platform UI toolkit for building native-quality iOS, Android, and Progressive Web Apps with HTML, CSS, and JavaScript.
https://ionicframework.com
MIT License
51.09k stars 13.51k forks source link

feat: Implement toast waiting lists or toast stacking. #20389

Open mattsteve opened 4 years ago

mattsteve commented 4 years ago

Feature Request

Ionic version: [x] 4.x or 5.x

Describe the Feature Request Currently if you present multiple toasts in the same position they show on top of one another which looks like a bug.

Describe Preferred Solution I would suggest one of two things:

  1. Implement toast stacking. If you present multiple toasts, they display in a list like the phone's notification drawer. This is what most UI libraries that display toasts do.

https://getbootstrap.com/docs/4.2/components/toasts/#stacking

Describe Alternatives

  1. Implement toast waiting lists. This means if you present two toasts in the same position at the same time, the second toast that was presented waits for the first toast to be dismissed, then it presents itself.

Related Code Here are examples in Bootstrap Vue: https://bootstrap-vue.js.org/docs/components/toast/#toasts-on-demand

liamdebeasi commented 4 years ago

Thanks for the feature request. We model the behavior of ion-toast after the MD spec, and that spec advises against stacking toast components on top of each other. As a result, toast stacking is not something we are looking to add at this time. https://material.io/components/snackbars/#behavior

Regarding the toast queue, can you explain your use case?

mattsteve commented 4 years ago

A queue would basically be the same behavior as "Consecutive snackbars" in the link you sent.

When multiple snackbar updates are necessary, they should appear one at a time.

That can be done today with this code:

const toast1 = await toastController.create();
const toast2 = await toastController.create();
await toast1.present();
await toast1.onDidDismiss();
await toast2.present();

My request is that instead of having to wait for onDidDismiss manually, toasts should just automatically handle consecutive display instead of displaying on top of one another.

So basically the above code could be simplified to this in the new design:

const toast1 = await toastController.create();
const toast2 = await toastController.create();
toast1.present();
toast2.present(); // <-- This promise will resolve after toast 1 onDidDismiss, and toast2 presents, instead of presenting the toast immediately and resolving.

Use case:

My problem is our product owners keep asking for toasts to display in very specific situations and are triggered by different pieces of code. If a bunch of these scenarios all occur at once or near the same time, you get a bunch of toasts overlaying each other.

The best solution is if I could leave it as is, the disconnected pieces of code can create toasts and display them as needed, and the toastController will automatically handle displaying them consecutively.

mattsteve commented 4 years ago

By the way, this would be per-position. So there's a queue for top, bottom, and center positions. Top, bottom, and center toasts can all display at the same time.

maxtacco commented 4 years ago

We would also appreciate ability to display toasts one under another even though it may go against "best practices". Right now displaying multiple toasts at the same time is not much helpful.

MaximS commented 3 years ago

Possible solution is here at stackblitz

DevonStern commented 2 years ago

Here is a barebones example of how to implement a toast queue in Ionic React.

danieljancar commented 1 year ago

I agree, the toast bars need a modernisation. Best scenario would be to give us a present mode option with f.x presentMode: stack | queue | list


There was a similar discussion about making toasts dismissible by swiping them away.

braincomb commented 2 months ago

Bump?

felixhirschfeld commented 1 month ago

bump :)

juanbrein commented 1 month ago

please!