NativeBase icon indicating copy to clipboard operation
NativeBase copied to clipboard

Toast Issue with React-navigation close app

Open eggybot opened this issue 9 years ago • 26 comments

Hi Guys, I'm not sure why this is happening, this issue is link on this error #836 evaluating 'this.toastInstance._root' Error when using Toast https://facebook.github.io/react-native/docs/upgrading.html

First of all I'm using the latest version of NativeBase and ReactNative. The Toast is perfectly working but there is one issue I found which the error evaluating 'this.toastInstance._root' Error when using Toast was showing when I do this steps.

First I newly open my app, then tried to test out the toast which perfectly works. Then I tried to go on different screen using the react-navigation and still it works fine. Then the error start I'm using this code.

        this.props.navigation.dispatch(NavigationActions.reset({
        index: 0,
        actions: [ NavigationActions.navigate({ routeName: 'Home'}) ]
        }));

As you can see, the back History index:0, is set to none for my navigation using react-navigation. In this setup if I use my Android back button, it will close the App. then if I open again my app, and tried to check out the Toast, the error shows up. It seems the <Root> tag on my main App is disappear which the error occur when I test the Toast again.

Do you know how can I fix this, every time I reopen the App, the error shows even I put the tag on my main component.

thanks,

eggybot avatar Jul 29 '17 20:07 eggybot

Are you just using the StackNavigator?

sankhadeeproy007 avatar Jul 30 '17 05:07 sankhadeeproy007

@sanketsahusoft

yes, I'm using stackNavigator for react-navigation. Its the same as the sample Toast in your documentation. But using the this.props.navigation.dispatch and setting index to 0, the error shows once you totally use the back button on the phone which close the application then when you go back it seems the Root has been remove.

I upload now in the my git the project sample which showing the error, https://github.com/eggybot/NativeBase_TOAST_Issue Just clone it and run npm install to test the sample. I will delete this once the issue is solve.

eggybot avatar Jul 30 '17 19:07 eggybot

any one can give me advice on this issue?

eggybot avatar Aug 04 '17 15:08 eggybot

Hi Guys, just an update when I upraded my React Native it shows a new error which is Cannot read property 'showToast' of null

can you check note me my this error show?

eggybot avatar Aug 10 '17 07:08 eggybot

I'm also experiencing this.toastInstance._root' error too...

ohtangza avatar Aug 15 '17 05:08 ohtangza

This is the screenshot error https://www.screencast.com/t/Gt6QCRcFs

it looks like the ROOT has conflict with react-navigation , I'm not sure if this is an issue with nativebase or react-navigation but clearly the Toast and ActionSheet has issue when I force back history and reopen the app again.

eggybot avatar Aug 15 '17 17:08 eggybot

Same problem here, it happens sometimes.

native-base: 2.3.1 react-native 0.47.1

douglasjunior avatar Aug 23 '17 14:08 douglasjunior

I'm seeing this issue when I go from native-base 2.1.4 to 2.1.5. I'm using RNRF.

native-base: 2.1.5 react-native 0.45.0 react 16.0.0-alpha.12 RNRF: 4.0.0-beta.19

kingbin avatar Aug 24 '17 14:08 kingbin

Personally I found this library more stable. Its not heavy weight https://react-native-training.github.io/react-native-elements

veubit avatar Sep 07 '17 16:09 veubit

I experience this issue as well. I am unable to figure out what causes it. It happens for both Toast and Action Sheet. screenshot_20170916-210242_01

mitesh-mutha avatar Sep 16 '17 15:09 mitesh-mutha

I'm facing with this issue exactly when close the app and then re-open the app, toast no longer working after that.

thienlhh avatar Oct 20 '17 10:10 thienlhh

While waiting for this fix, I have workaround by using this package to exit the app. Just apply when root component unmounting.

Hope this help.

thienlhh avatar Nov 17 '17 10:11 thienlhh

Did you add Root as per documents? I added root to wrap my stack and the issue went away.

<NativeBase.Root>

https://docs.nativebase.io/Components.html#Toast

I added Root and it fixed the error message.

azat-co avatar Nov 21 '17 01:11 azat-co

See my solution here

kesiena115 avatar Nov 22 '17 06:11 kesiena115

Not present with the latest version of NativeBase (2.3.5). Closing this issue. Let us know if you are facing any issue.

Gif

toast

akhil-ga avatar Jan 09 '18 08:01 akhil-ga

@akhil-geekyants the problem occurs when using the left back button on Android, not closing completelly the app. I'm using NativeBase (2.4.2) and the problem is still present.

Btw, I solved by adding this to my main component:

  componentWillUnmount() {
    Toast.toastInstance = null;
  }

edumelzer avatar May 11 '18 18:05 edumelzer

@edumelzer We will re-check on this

SupriyaKalghatgi avatar May 14 '18 05:05 SupriyaKalghatgi

Same for me on native base v2.3.10

alwex avatar May 14 '18 05:05 alwex

@alwex can you try edumelzer's solution https://github.com/GeekyAnts/NativeBase/issues/1121#issuecomment-388443807

akhil-ga avatar May 14 '18 08:05 akhil-ga

@akhil-geekyants this solution works, but it is more a workaround than a real solution

alwex avatar May 15 '18 09:05 alwex