question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

feat: allow for custom ion-toast positioning

See original GitHub issue

Feature Request

Ionic version: [x] 4.x

Describe the Feature Request Currently with the implementation of toasts in Ionic v4, we have no way of adding some padding or margin to an ion-toast. I’d like to be able to customize this position in order to adhere to the material design principle outlined here.

Describe Preferred Solution Ideally, this would be something that could be added in the CSS custom properties.

Issue Analytics

  • State:open
  • Created 5 years ago
  • Reactions:23
  • Comments:14

github_iconTop GitHub Comments

31reactions
jbae1024commented, Mar 18, 2019

I do not know… I use it like this. Is there any other problem?

css

.md .tabs-bottom {
  transform: translateY(-56px) !important;
}
.ios .tabs-bottom {
  transform: translateY(-50px) !important;
}
.md .header-top {
  top: 56px !important;
}
.ios .header-top {
  top: 44px !important;
}

ts

const toast = await this.toastController.create({
            message: 'This is message',
            position: 'bottom',
            duration: 1000,
            color: 'warning',
            cssClass: 'tabs-bottom'
        });
        toast.present();
4reactions
map-locommented, Aug 19, 2021

@darkdread I found a solution for Ionic 5.x. Provide a custom enter animation including an offset for the tabs bar.

// ...
export const iosEnterAnimation = (baseEl: ShadowRoot, position: string, offset = 10): Animation => {
    const baseAnimation = createAnimation();
    const wrapperAnimation = createAnimation();

    const hostEl = baseEl.host || baseEl;
    const wrapperEl = baseEl.querySelector('.toast-wrapper') as HTMLElement;

    const bottom = `calc(-${offset}px - var(--ion-safe-area-bottom, 0px))`;
    const top = `calc(${offset}px + var(--ion-safe-area-top, 0px))`;

    wrapperAnimation.addElement(wrapperEl);

    switch (position) {
        case 'top':
            wrapperAnimation.fromTo('transform', 'translateY(-100%)', `translateY(${top})`);
            break;
        case 'middle':
            const topPosition = Math.floor(
                (hostEl as Element).clientHeight / 2 - wrapperEl.clientHeight / 2
            );
            wrapperEl.style.top = `${topPosition}px`;
            wrapperAnimation.fromTo('opacity', 0.01, 1);
            break;
        default:
            wrapperAnimation.fromTo('transform', 'translateY(100%)', `translateY(${bottom})`);
            break;
    }
    return baseAnimation
        .addElement(hostEl)
        .easing('cubic-bezier(.155,1.105,.295,1.12)')
        .duration(400)
        .addAnimation(wrapperAnimation);
};
// opts used as toastController.create(opts)
if (this.tabsVisible) {
    opts.enterAnimation = (baseEl: ShadowRoot) => iosEnterAnimation(baseEl, opts.position, 60)
}
const toast = await toastController.create(opts);
// ...
Read more comments on GitHub >

github_iconTop Results From Across the Web

ToastController custom position in ionic - css - Stack Overflow
We are creating Ionic-Native mobile app.We are using ToastController (ToastController).We used position: ' ...
Read more >
ion-toast Component: A Dismissible App Notification Alert
Toasts can be positioned at the top, bottom or middle of the viewport. The position can be passed upon creation. The possible values...
Read more >
How to create a custom toast component with React
css file. To see what the toast component looks like, let's apply some properties, such as position , to be passed as props ......
Read more >
How to Show and Customize Toast Notification in Ionic 6 App
... on integrating and customizing the Ionic Toast UI component using its custom properties, including how to change the position of toast, ...
Read more >
Positioning toast | React-Toastify - GitHub Pages
If a position is set on a toast , the one defined on ToastContainer will be replaced. The following values are allowed: top-right,...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found