feat(toast): add lightweight, Sonner style Toast Component #502
+806
−0
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Pull Request
Description
This PR introduces a lightweight Toast component built on top of the existing
@rn-primitives/toastprimitive.The goal is to provide a simple, polished, and ergonomic toast system for React Native that aligns with the philosophy of
react-native-reusables:The implementation follows a Sonner-inspired API and integrates naturally with the existing
PortalHost, Zustand store, and Reanimated-based animation patterns.Motivation:
I was looking for a Toast component within react-native-reusables. After searching the issues, I found this comment mentioning that it is currently low priority.
I decided to implement one using @rn-primitives/toast for my own production app and wanted to contribute it back, as this library has helped me significantly.
I understand this implementation might not perfectly align with the specific architecture the maintainers have in mind. However, I hope this PR can serve as a solid foundation (or reference) to speed up the work for an official Toast component. Thank you for your hard work!
Features
toast()API (toast.success,toast.error,toast.info)toast.promise()for async workflowsreact-native-reanimatedTested Platforms
Affected Apps/Packages
Screenshots
Notes
Dependencies
This component does not introduce any new dependencies. It relies only on peer dependencies already likely present in the project:
zustand— state managementreact-native-reanimated— animationsreact-native-safe-area-context— positioninglucide-react-native— icons@rn-primitives/toast— primitive@rn-primitives/portal— portal renderingUsage
Mount the
Toastercomponent once at the root (alongsidePortalHost):Trigger toasts imperatively:
Configuration
Can be customized via props on the component:
Limitations / Non-goals
To keep the component minimal, the following are intentionally out of scope for this PR:
react-native-gesture-handleroverhead)Summary by CodeRabbit
Release Notes