iOS Swift : Material Snackbar showing behind child popup view

557 Views Asked by At

I am trying to use material snackbar. Everything works fine if snackbar toast message is shown directly on a view controller. However when a child pop up view is appended to the view (view.addSubView), and the toast is triggered from the child popup view controller, the toast message is hidden ie., shown behind the popup view (Toast can be seen after dismissing the child popup view)

Has anyone come across this issue? How do I make sure material snackbar toast is always visible no matter where it is triggered from?

1

There are 1 best solutions below

0
On

I figured it out. The magic was with the usage of MDCSnackbarManager.setPresentationHostView. I specifically set window as presentationHostView.

if let appDelegate = UIApplication.shared.delegate as? AppDelegate, let window = appDelegate.window {
    MDCSnackbarManager.setPresentationHostView(window)
}

As per documentation, if the library fails to figure out the presentationHostView as intended, we can specifically set it.