Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Calling setstate doesn't show snackbar. #81

Closed
kundan1301 opened this issue Jun 19, 2018 · 5 comments
Closed

Calling setstate doesn't show snackbar. #81

kundan1301 opened this issue Jun 19, 2018 · 5 comments

Comments

@kundan1301
Copy link

kundan1301 commented Jun 19, 2018

Calling setstate doesn't show snackbar.

this.setState({ loading: true });  
const res = await Utils.verifyOtp(code);  
this.setState({ loading: false});  
Snackbar.show({title:message,duration:duration,backgroundColor:backGroundColor});

Above code doesn't show snackbar. But Below code show snackbar

//this.setState({ loading: true });  
const res = await Utils.verifyOtp(code);  
//this.setState({ loading: false});  
Snackbar.show({title:message,duration:duration,backgroundColor:backGroundColor});
@kundan1301
Copy link
Author

kundan1301 commented Jun 20, 2018

This works as well

setTimeout(()=>{
  Snackbar.show({title:message,duration:duration,backgroundColor:backGroundColor});
}, 10)

@cooperka
Copy link
Owner

Hi @kundan1301, that's very strange. Are there any routes or screens that are added or removed based on the state (such as a modal that pops up)?

If you could link to a working example app that would help me diagnose the issue. Feel free to fork and edit the official example app if that's easier.

@kundan1301
Copy link
Author

Hello @cooperka, Yes I am adding a modal to show loader. Once network call is completed const res = await Utils.verifyOtp(code); // this is network call , I am trying to show error or success in snackbar.

@cooperka
Copy link
Owner

Unfortunately, that won't currently work -- see #28 for details.

The snackbar attaches itself to the top screen, and if that screen is a modal, the snackbar will go away along with the modal. Whether this Android behavior is a "bug" or a "feature" depends on who you ask 😉

For now, you could either show the loading indicator using something other than a modal, or you could add a slight delay (as you suggested) to make sure the snackbar attaches to the screen below the modal.

@cooperka
Copy link
Owner

Closing as duplicate of #28; feel free to reply on either issue if you have any questions. Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants