gluestack / gluestack-ui

React & React Native Components & Patterns (copy-paste components & patterns crafted with Tailwind CSS (NativeWind))
https://gluestack.io/
MIT License
2.76k stars 121 forks source link

useToast not available when used in a component rendered inside a Modal #1849

Open milesingrams opened 8 months ago

milesingrams commented 8 months ago

Description

useToast not available when used in a component rendered inside a Modal

CodeSandbox/Snack link

No response

Steps to reproduce

Create a component that calls useToast and put in inside a

gluestack-ui Version

@gluestack-ui/themed 1.1.8

Platform

Other Platform

No response

Additional Information

This is probably because the overlay provider renders modals outside the toast provider? Not 100% sure but a guess. Ideally useToast could be used by modals or any other overlay.

Viraj-10 commented 8 months ago

Hey @milesingrams , Thanks for reporting the issue. We will have a look.

gregamann commented 8 months ago

Hey ! Same behaviour for me with a screen rendered as a modal (presentation: 'modal') Toast appears behind (when I drag down modal to close it)

Capture d’écran 2024-03-03 à 15 38 24
vaniyokk commented 8 months ago

Same issue for React Native CLI, if using useToast inside Modal. It's not a presentation issue, it's something related to Modal vs Toast rendering context / providers.

Error is:

63848
ruettenm commented 8 months ago

Hi, I have the same issue like @vaniyokk. It would be nice if it's possible to use a toast for a modal.

tmaly1980 commented 7 months ago

Hey @milesingrams , Thanks for reporting the issue. We will have a look.

Any update? It's been a month since this was reported and I can't use toasts when a modal is open (it appears underneath).

vaniyokk commented 7 months ago

I was able to get rid of AnimatePresence null pointer exception by monkey-patching node_modules/@gluestack-ui/actionsheet/src/Actionsheet.tsx and wrapping children into ToastProvider exported from node_modules/@gluestack-ui/toast/src/Toast.tsx.

60281

I'm not sure about consequences to performance and design but seems like it helps to mitigate all errors.

BTW I don't have issue with Toast being shown under the modal, as @gregamann reported.

85404

@Viraj-10 maybe you can consider adding Toast providers to every native modal components to allow Toast usage inside?

lhguerra commented 7 months ago

That sounds weird, we shouldn't need more than one toast provider. Or it sould be exported so we can at least use it in these weird contexts.

vaniyokk commented 7 months ago

@lhguerra it's a common pattern due to nature of native modals in RN and pretty much every toast library relying on separate toast providers inside context of native modals https://github.com/calintamas/react-native-toast-message/blob/HEAD/docs/modal-usage.md https://github.com/arnnis/react-native-toast-notifications?tab=readme-ov-file#--how-to-show-toast-inside-a-modal https://github.com/backpackapp-io/react-native-toast?tab=readme-ov-file#providerkey-string--optional

I believe there is no better solution out there, and probably gluestack could handle this as well on library level, implementing toast providers in modal components.

zainuwachtig commented 5 months ago

Any updates on this?