Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 14 additions & 13 deletions src/components/Toast.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -74,20 +74,7 @@ export const Toast: FC<Props> = ({
}) => {
const insets = useSafeAreaInsets();
const { width, height } = useWindowDimensions();

useVisibilityChange(
() => {
onToastShow?.(toast);
},
() => {
onToastHide?.(toast);
},
toast.visible
);

const isSystemDarkMode = useColorScheme() === 'dark';
const isDarkMode =
overrideDarkMode !== undefined ? overrideDarkMode : isSystemDarkMode;

const [toastHeight, setToastHeight] = useState<number>(
toast?.height ? toast.height : DEFAULT_TOAST_HEIGHT
Expand All @@ -96,6 +83,9 @@ export const Toast: FC<Props> = ({
toast?.width ? toast.width : width - 32 > 360 ? 360 : width - 32
);

const isDarkMode =
overrideDarkMode !== undefined ? overrideDarkMode : isSystemDarkMode;

const startingY = useMemo(
() =>
toast.position === ToastPosition.TOP
Expand All @@ -109,6 +99,7 @@ export const Toast: FC<Props> = ({
const offsetY = useSharedValue(startingY);

const onPress = () => onToastPress?.(toast);

const dismiss = useCallback((id: string) => {
toasting.dismiss(id);
}, []);
Expand Down Expand Up @@ -213,6 +204,16 @@ export const Toast: FC<Props> = ({
toast.animationConfig,
]);

useVisibilityChange(
() => {
onToastShow?.(toast);
},
() => {
onToastHide?.(toast);
},
toast.visible
);

useEffect(() => {
setToastHeight(toast?.height ? toast.height : DEFAULT_TOAST_HEIGHT);
}, [toast.height]);
Expand Down
2 changes: 1 addition & 1 deletion src/components/Toasts.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -60,8 +60,8 @@ export const Toasts: FunctionComponent<Props> = ({
left: insets.left + (extraInsets?.left ?? 0),
right: insets.right + (extraInsets?.right ?? 0),
bottom: insets.bottom + (extraInsets?.bottom ?? 0) + 16,
pointerEvents: 'box-none',
}}
pointerEvents={'box-none'}
>
{toasts.map((t) => (
<Toast
Expand Down
2 changes: 1 addition & 1 deletion src/index.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
export { useToaster } from './core/use-toaster';
export { Toasts } from './components';
export * from './headless';
export { ToastPosition, ToastAnimationType } from './core/types';
export { ToastPosition, type ToastAnimationType } from './core/types';