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

Snackbar goes offscreen with modals/back button [Android] #28

Open
ayazhussein opened this issue Apr 20, 2017 · 13 comments
Open

Snackbar goes offscreen with modals/back button [Android] #28

ayazhussein opened this issue Apr 20, 2017 · 13 comments
Labels

Comments

@ayazhussein
Copy link

ayazhussein commented Apr 20, 2017

SnackBar.show({
        title: "Timeout, reverting to old one...",
        duration: SnackBar.LENGTH_LONG,
        backgroundColor: "#493d46",
});
this.props.navigation.dispatch({
    type: NavigationActions.BACK,
});

It does show on IOS but it doesnt on Android...
using

react-navigation

@cooperka

@cooperka cooperka added the bug label Apr 20, 2017
@cooperka
Copy link
Owner

cooperka commented Apr 20, 2017

Hmm, I haven't tested this yet but I'm guessing the snackbar gets attached to the current scene and goes offscreen along with the scene as it gets popped. Thanks for the bug report! I'll see what can be done.

I think the best solution would be to find the real root view that everything is nested under and show the snackbar on that one, instead of the current activity's view. Hopefully this is possible with RN.

@cooperka
Copy link
Owner

cooperka commented Apr 20, 2017

Official workaround:

In the meantime, I'd suggest just adding a setTimeout before showing the snackbar so it gets attached to the scene below instead of the scene being popped.

@iRoachie
Copy link
Contributor

I've been using the setTimeout method for dismissing modals too. Works great. Currently have it set at 200ms

@ayazhussein
Copy link
Author

I don't know if it's a bug or it's on my end but if I call Snackbar.show() directly after closing a modal, it doesn't show but if I close the modal and do a network call and then show Snackbar on the response, it does show...

@ayazhussein
Copy link
Author

although on IOS does work :D, the bug is only on android...

@iRoachie
Copy link
Contributor

iRoachie commented Apr 20, 2017

This is what i'm doing. I have the parent showing the snackbar instead.

snackbar modals

  // In modal
  async saveEdits(user: User) {
    this.setState({
      workingOverlayShowing: true
    })

    // Simulate network request
    this.props.updateUserInfo(user)
    await new Promise((resolve: any) => setTimeout(resolve, 2000))

    this.setState({
      workingOverlayShowing: false
    })

    this.props.showSuccessMessage()
  }

// In Parent
  async showSuccessMessage() {
    this.toggleEditModal()

    await new Promise((resolve: any) => setTimeout(resolve, 100))

    Snackbar.show({
      title: 'Changes saved',
      duration: Snackbar.LENGTH_SHORT
    })
  }

@cooperka
Copy link
Owner

@ayazhussein it's definitely a bug; the snackbar appears on the modal that you just dismissed when really it should be appearing on top of everything irrespective of what's currently on top of the stack. setTimeout is a decent workaround, but I'll try to fix this in the library soon.

@mahomahoxd
Copy link

mahomahoxd commented Oct 18, 2017

Is this being fixed? I'm having the same issue with closing the modal (I think the animation is taking long so the snackbar shows on the closed modal). I fixed it by the setTimeout function, although it doesn't feel as clean as it should be. I might be able to take a look if you can point me where I should look

@cooperka
Copy link
Owner

Thanks for the offer @mahomahoxd -- support for modals was added in #17 and this is a remaining bug that hasn't been addressed yet. If you could help I'd really appreciate it; that PR would be a good place to start looking. Cheers.

@cooperka cooperka changed the title Snackbar doesn't appear if you navigate back on Android but it does on IOS Snackbar goes offscreen if you navigate back [Android] Jan 20, 2018
@cooperka cooperka changed the title Snackbar goes offscreen if you navigate back [Android] Snackbar goes offscreen when used with modals [Android] Jul 3, 2020
@cooperka cooperka changed the title Snackbar goes offscreen when used with modals [Android] Snackbar goes offscreen with modals/back button [Android] Jul 3, 2020
@sabrimev
Copy link

I was having same issue. It didn't appear after loading layout. So I just set timeout like this;

setTimeout(() => { Snackbar.show({ text: errorText, duration: Snackbar.LENGTH_LONG, }) }, 300)

@Minishlink
Copy link

I don't really like having a timeout so I've forced the snackbar to show on the main view instead of the modal in the areas of the app where there is a loading overlay. https://gist.github.com/Minishlink/fc60bce597cf3564d442c367418a89bf

@cooperka
Copy link
Owner

cooperka commented Mar 8, 2021

Hopefully this PR improves things: #179 (released in v2.4.0)

@iamrohitagg
Copy link

This issue occurs for me only on Android. I am showing a Modal as loader for my app and whenever the modal is open, the SnackBar does now show.
I had to use timeout for getting it work. Hopefully the issue is resolved in latest build.

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

No branches or pull requests

7 participants