react-native-toast-message icon indicating copy to clipboard operation
react-native-toast-message copied to clipboard

Custom Toast messages are never unmounted

Open go-sean-go opened this issue 3 years ago • 4 comments

Describe the bug When using a custom toast component, i.e.

import CustomToastComponent from '../components/customToastComponent';

<Toast config={{
  'custom': CustomToastComponent
}} />

...the custom component is never unmounted. Specifically, React Hooks return functions are never called, i.e.

const CustomToastComponent = () => {
  useEffect(() => {
    console.log('mounting Toast!'); // <~~ called on Toast.show()
    return () => {
      console.log('unmounting Toast!'); // <~~ NEVER called, even on Toast.hide() or manual dismiss by the user
    };
  }, []);
};

export default CustomToastComponent;

This creates various challenges in managing the lifecycle of the Toast and state.

Steps to reproduce

  1. Implement custom toast component and register it with <Toast config={} />
  2. Call Toast.show() - LOG: mounting Toast!
  3. After some duration, call Toast.hide() - no LOG events

Expected behavior Toast.hide() should unmount the component after it's off-screen, i.e. LOG: unmounting Toast!.

Screenshots n/a

Code sample See above.

Environment (please complete the following information):

  • OS: iOS 15.2 (did not test on other platforms)
  • react-native-toast-message version: 2.1.5
  • react-native version: 0.69.4

Additional context n/a

go-sean-go avatar Sep 07 '22 17:09 go-sean-go

I am also facing same issue. Items behind the custom toast are not clickable.

ajaysaini-sgvu avatar Oct 14 '22 05:10 ajaysaini-sgvu

I'm running into the same issue here now. has there been any progress around this?

adam-govan avatar May 08 '23 17:05 adam-govan

Revisiting after ~6 months, maybe some kind of config param could drive this (destroyOnHide, idk).

go-sean-go avatar May 08 '23 17:05 go-sean-go

Revisiting after ~6 months, maybe some kind of config param could drive this (destroyOnHide, idk).

Agreed! We could have an extra config like mentioned.

Same issue still present. For me if I create a custom toast and call it with some text and then hide it and call it again with new text, the old toast is shown with the previous text

CodeWithRomaen avatar Dec 29 '23 23:12 CodeWithRomaen