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

feat(Toast): use View Transition API for Toast animations #7631

Merged
merged 22 commits into from
Feb 7, 2025

Conversation

reidbarber
Copy link
Member

@reidbarber reidbarber commented Jan 17, 2025

Removes useToast's existing animation API in favor of using the browser's View Transition API to animate toasts.

✅ Pull Request Checklist:

  • Included link to corresponding React Spectrum GitHub Issue.
  • Added/updated unit tests and storybook for this change (for new code or code which already has tests).
  • Filled out test instructions.
  • Updated documentation (if it already exists for this component).
  • Looked at the Accessibility Practices for this feature - Aria Practices

📝 Test Instructions:

Test the entrance and exist transitions in toast stories, including different placements, closing via timeout, and closing programmatically.

🧢 Your Project:

@rspbot
Copy link

rspbot commented Jan 17, 2025

@rspbot
Copy link

rspbot commented Jan 21, 2025

@reidbarber reidbarber changed the title WIP: feat(Toast): use View Transition API for Toast animations feat(Toast): use View Transition API for Toast animations Jan 22, 2025
@rspbot
Copy link

rspbot commented Jan 27, 2025

@rspbot
Copy link

rspbot commented Jan 28, 2025

Copy link
Member

@snowystinger snowystinger left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

those animations look so nice now!

Looks like we no longer focus the next toast when we remove a toast from the list. I checked against main.

@rspbot
Copy link

rspbot commented Jan 30, 2025

snowystinger
snowystinger previously approved these changes Jan 31, 2025
Copy link
Member

@snowystinger snowystinger left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should toasts that timeout to leave also animate?

otherwise looks good, focus of next toast appears to be working again

@rspbot
Copy link

rspbot commented Feb 3, 2025

@rspbot
Copy link

rspbot commented Feb 5, 2025

snowystinger
snowystinger previously approved these changes Feb 7, 2025
yihuiliao
yihuiliao previously approved these changes Feb 7, 2025
@reidbarber reidbarber dismissed stale reviews from yihuiliao and snowystinger via e7a18b2 February 7, 2025 15:42
@rspbot
Copy link

rspbot commented Feb 7, 2025

@rspbot
Copy link

rspbot commented Feb 7, 2025

## API Changes

@react-stately/toast

/@react-stately/toast:ToastQueue

 ToastQueue <T> {
   add: (T, ToastOptions) => void
   close: (string) => void
   constructor: (ToastStateProps) => void
   pauseAll: () => void
-  remove: (string) => void
   resumeAll: () => void
   subscribe: (() => void) => void
   visibleToasts: Array<QueuedToast<T>>
 }

/@react-stately/toast:ToastState

 ToastState <T> {
   add: (T, ToastOptions) => string
   close: (string) => void
   pauseAll: () => void
-  remove: (string) => void
   resumeAll: () => void
   visibleToasts: Array<QueuedToast<T>>
 }

/@react-stately/toast:QueuedToast

 QueuedToast <T> {
-  animation?: 'entering' | 'queued' | 'exiting' | null
   content: T
   key: string
   onClose?: () => void
   priority?: number
   timer?: Timer
 }

/@react-stately/toast:ToastStateProps

 ToastStateProps {
-  hasExitAnimation?: boolean
   maxVisibleToasts?: number
+  wrapUpdate?: (() => R) => R
 }

@reidbarber reidbarber added this pull request to the merge queue Feb 7, 2025
Merged via the queue into main with commit ff300df Feb 7, 2025
30 checks passed
@reidbarber reidbarber deleted the remove-toast-hooks-animation branch February 7, 2025 21:50
@wingkwong
Copy link

@reidbarber Hello. Our HeroUI toast is using the data attributes (e.g. data-[animation=exiting]) to define the animation in tailwindcss (see here). May I know is there way I could get the toast animation (e.g. exiting) without using view transitions?

@devongovett
Copy link
Member

@wingkwong the previous data attributes were incomplete and buggy, and to fix them we realized that we'd basically need to reinvent an animation library like Framer Motion or React Transition Group, which have much more advanced support for entry/exit animations. We'd recommend using one of those instead.

This is more complicated than the animation states we offer for things like popovers/modals because there is a list of items rather than only a single element to transition. Framer Motion also supports layout animations, which smoothly transition the positions of neighboring items when a new one is added or an item is removed. CSS View Transitions also support this natively in the browser, and with support for that coming along, we decided to avoid adding this complexity to the Toast component. This keeps the component smaller and gives you flexibility to choose an animation solution that suits your needs.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants