From d6f899041e5553fa76b5a03b5bb8f0ba800da3b3 Mon Sep 17 00:00:00 2001 From: Gunnar Torfi Date: Sun, 27 Oct 2024 15:34:26 +0000 Subject: [PATCH 1/2] fix: conditional full window overlay --- src/toaster.tsx | 70 ++++++++++++++++++++++++++++++++++++++----------- 1 file changed, 55 insertions(+), 15 deletions(-) diff --git a/src/toaster.tsx b/src/toaster.tsx index fbad21a..718fad8 100644 --- a/src/toaster.tsx +++ b/src/toaster.tsx @@ -21,11 +21,31 @@ let wiggleHandler: typeof toast.wiggle; export const Toaster: React.FC = ({ ToasterOverlayWrapper, - ...props + ...toasterProps }) => { + const toastsCounter = React.useRef(1); + const toastRefs = React.useRef>>({}); + const [toasts, setToasts] = React.useState([]); + + const props = React.useMemo(() => { + return { + ...toasterProps, + toasts, + setToasts, + toastsCounter, + toastRefs, + }; + }, [toasterProps, toasts]); + + if (toasts.length === 0) { + return ; + } + if (ToasterOverlayWrapper) { return ( - {} + + + ); } @@ -40,7 +60,16 @@ export const Toaster: React.FC = ({ return ; }; -export const ToasterUI: React.FC = ({ +export const ToasterUI: React.FC< + ToasterProps & { + toasts: ToastProps[]; + setToasts: React.Dispatch>; + toastsCounter: React.MutableRefObject; + toastRefs: React.MutableRefObject< + Record> + >; + } +> = ({ duration = toastDefaultValues.duration, position = toastDefaultValues.position, offset = toastDefaultValues.offset, @@ -56,12 +85,12 @@ export const ToasterUI: React.FC = ({ theme, autoWiggleOnUpdate, richColors, + toasts, + setToasts, + toastsCounter, + toastRefs, ...props }) => { - const [toasts, setToasts] = React.useState([]); - const toastsCounter = React.useRef(1); - const toastRefs = React.useRef>>({}); - addToastHandler = React.useCallback( (options) => { const id = @@ -122,7 +151,15 @@ export const ToasterUI: React.FC = ({ return id; }, - [autoWiggleOnUpdate, duration, toasts, visibleToasts] + [ + autoWiggleOnUpdate, + duration, + setToasts, + toastRefs, + toasts, + toastsCounter, + visibleToasts, + ] ); const dismissToast = React.useCallback< @@ -160,7 +197,7 @@ export const ToasterUI: React.FC = ({ return id; }, - [toasts] + [setToasts, toasts, toastsCounter] ); dismissToastHandler = React.useCallback( @@ -170,12 +207,15 @@ export const ToasterUI: React.FC = ({ [dismissToast] ); - wiggleHandler = React.useCallback((id) => { - const toastRef = toastRefs.current[id]; - if (toastRef && toastRef.current) { - toastRef.current.wiggle(); - } - }, []); + wiggleHandler = React.useCallback( + (id) => { + const toastRef = toastRefs.current[id]; + if (toastRef && toastRef.current) { + toastRef.current.wiggle(); + } + }, + [toastRefs] + ); const { unstyled } = toastOptions; From d074787f9808fd4c8e889be4618a95328eaa7e17 Mon Sep 17 00:00:00 2001 From: Gunnar Torfi Date: Sun, 27 Oct 2024 15:37:09 +0000 Subject: [PATCH 2/2] chore: release 0.16.0-beta.0 --- CHANGELOG.md | 7 +++++++ package.json | 2 +- 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 8475eb2..3a8b6a0 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,12 @@ +# [0.16.0-beta.0](https://github.com/gunnartorfis/sonner-native/compare/v0.15.0...v0.16.0-beta.0) (2024-10-27) + + +### Bug Fixes + +* conditional full window overlay ([d6f8990](https://github.com/gunnartorfis/sonner-native/commit/d6f899041e5553fa76b5a03b5bb8f0ba800da3b3)) + # [0.15.0](https://github.com/gunnartorfis/sonner-native/compare/v0.14.2...v0.15.0) (2024-10-04) diff --git a/package.json b/package.json index 4348629..a4706a5 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "sonner-native", - "version": "0.15.0", + "version": "0.16.0-beta.0", "description": "An opinionated toast component for React Native. A port of @emilkowalski's sonner.", "source": "./src/index.tsx", "main": "./lib/commonjs/index.js",