gluestack-ui icon indicating copy to clipboard operation
gluestack-ui copied to clipboard

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

Open milesingrams opened this issue 1 year ago • 12 comments

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 <Modal>

gluestack-ui Version

@gluestack-ui/themed 1.1.8

Platform

  • [X] Expo
  • [ ] React Native CLI
  • [ ] Next
  • [ ] Web
  • [ ] Android
  • [ ] iOS

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.

milesingrams avatar Feb 28 '24 04:02 milesingrams

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

Viraj-10 avatar Mar 01 '24 07:03 Viraj-10

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

gregamann avatar Mar 03 '24 14:03 gregamann

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

vaniyokk avatar Mar 04 '24 14:03 vaniyokk

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

ruettenm avatar Mar 27 '24 20:03 ruettenm

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).

tmaly1980 avatar Apr 03 '24 15:04 tmaly1980

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?

vaniyokk avatar Apr 03 '24 22:04 vaniyokk

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.

lhguerra avatar Apr 04 '24 14:04 lhguerra

@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.

vaniyokk avatar Apr 04 '24 14:04 vaniyokk

Any updates on this?

zainuwachtig avatar May 29 '24 11:05 zainuwachtig