4

Goal: I'm trying to create a custom sheet that behaves more or less like a normal sheet.

How: I'm using an overlay on top of my main view and changing its content to the view I need to display.

Like so:

MainView()
    .overlay {
        CustomSheet(content: SomeView())
    }

Problem: When I open a normal sheet, the sheet goes on top of everything, including the overlay that's on the main view.

Question: How can I make the overlay open on top of every view (including a sheet and a fullScreenCover) the same way a normal sheet does?

The solution has to work on iOS 15 and above

Thanks :)

Ori
  • 567
  • 3
  • 9
  • 1
    For this you will likely have to look into creating multiple windows for your app. So that your app runs in one window and your "overlay" view thing will be displayed in a separate window and show above everything else. – Fogmeister Jan 05 '23 at 15:19
  • Oh, yea that might be the solution. Is it possible on iOS? Do you have any resources that might help me with that? – Ori Jan 05 '23 at 15:25
  • This might be helpful... https://stackoverflow.com/questions/46975181/is-it-possible-that-an-ios-application-can-have-more-than-one-window – Fogmeister Jan 05 '23 at 15:31
  • https://www.fivestars.blog/articles/swiftui-windows/ – Peter Lapisu Jun 27 '23 at 13:41

1 Answers1

0

Here is an implementation for a notification banner, based on the solution on the five star blog.

https://github.com/DominikButz/SwiftUI_NotificationBanner

unfortunately, this solution currently only works on iOS.

domi852
  • 497
  • 1
  • 4
  • 13