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.

Example of custom animation in toasts

See original GitHub issue

Hello, I was wondering if you were so kind as to share some example of custom animation for the Toast component, for example, I have been reading the documentation and I have not found anything regarding the subject, I know I can do it using the component <b-toaster> but I have not managed to meet my expectations. For example, in my case, I am trying to make the notification appear with a translation from right to left and disappear with the opposite movement.

Could someone help me by showing me an example of how to achieve a custom animation? Thank you very much in advance.

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Comments:6 (2 by maintainers)

github_iconTop GitHub Comments

2reactions
leo95workscommented, May 19, 2020

Ok, I have continued my attempts and have managed to avoid using @keyframes for animation in this way, but I still cannot achieve the final animation when the toast is hidden, thus achieving the translation animation from right to left, but I can’t make the final from left to right. Any suggestion?

.b-toaster {
  &.b-toaster-top-right,
  &.b-toaster-top-left,
  &.b-toaster-bottom-right,
  &.b-toaster-bottom-left {
    .b-toast {
      transition: transform .175s;

      &.b-toaster-enter-active,
      &.b-toaster-leave-active,
      &.b-toaster-move {
        transition: none;
      }

      &.b-toaster-enter {
        transform: translateX(100%);
      }

      &.b-toaster-enter-to,
      &.b-toaster-enter-active {
        .toast.fade {
          transition-delay: 0.175s;
        }
      }

      &.b-toaster-enter-to {
      }

      &.b-toaster-leave-active {
        position: absolute;
        transition-delay: 0.175s;

        .toast.fade {
          transition-delay: 0s;
        }
      }

      &.b-toaster-leave-to {
      }
    }
  }
}
1reaction
leo95workscommented, May 19, 2020

@tmorehouse Thank you very much for your interest in my question. The truth is that I had not responded before because I like to try all possible alternatives and ways before giving a comment. I have tried in various ways to meet my expectations regarding this question. But the truth is that I have not succeeded. Please, if you could analyze what I am doing and see what I have wrong:

@keyframes right {
  from {
    transform: translateX(0%);
  }

  to {
    visibility: hidden;
    transform: translateX(100%);
  }
}

@keyframes left {
  from {
    transform: translateX(100%);
  }

  to {
    visibility: hidden;
    transform: translateX(0%);
  }
}

.b-toaster {
  &.b-toaster-top-right {
    .b-toast {
      &.b-toaster-enter-active,
      &.b-toaster-leave-active,
      &.b-toaster-move {
        animation: left 2s;
      }

      &.b-toaster-enter {
      }

      &.b-toaster-enter-to,
      &.b-toaster-enter-active {
        .toast {
          &.fade {
            transition-delay: .175s;
          }
        }
      }

      &.b-toaster-enter-to {
      }

      &.b-toaster-leave-active {
        position: absolute;
        transition-delay: .175s;

        .toast.fade {
          transition-delay: 0s;
        }
      }

      &.b-toaster-leave-to {
      }
    }
  }
}

In essence what I want to get as a comment in my initial question, is that the toast appears with an animation of translation from right to left, and is hidden with an opposite movement (from left to right). With this, what I have achieved is the following:

notification

In this way I have achieved part of what I want, but I cannot make the opposite movement run when I close the toast. In fact, I don’t know if this way is convenient to achieve what I want, since I may not have to use @keyframes for the animation.

Please, if you could help me with this problem, I would appreciate it. Thank you very much in advance.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Custom animation for Toast enter/exit? - android
Toasts are displayed using a system template that can't be changed so short answer is no you cant change the toast animation. however...
Read more >
Implementing animated toasts in React - LogRocket Blog
Learn how to make a toast component with animations using React, Framer Motion, and Zustand, plus some custom Hooks for good measure.
Read more >
Animation in React Toast component - Syncfusion
React Toasts support custom animations for both shows and hide actions from the ... The sample demonstrates some types of animation that suits...
Read more >
Custom & Reusable Toast Component with Angular ...
Custom & Reusable Toast Component with Angular Animations, Async Pipe, ... Feel free to use my SCSS package on npm for this example, ......
Read more >
Define a custom enter and exit animation | React-Toastify
When it comes to animation the possibility are endless and it doesn't need to be complicated! Starting v7, css animations just works out...
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