Skip to content

Instantly share code, notes, and snippets.

@IsaAliev
Last active August 12, 2021 17:40
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save IsaAliev/3392a8e55ca74d4e214c5c81f05be66c to your computer and use it in GitHub Desktop.
Save IsaAliev/3392a8e55ca74d4e214c5c81f05be66c to your computer and use it in GitHub Desktop.
// 1 - Create class that will be used to pass new modal to root view
class FullScreenModalProvider: ObservableObject {
var content: AnyView? = nil {
willSet { objectWillChange.send() }
}
}
struct MainView: View {
// 2 - Add EnvironmentObject variable to root view
@EnvironmentObject var fullScreenModal: FullScreenModalProvider
var body: some View {
// 3 - Wrap TabView in ZStack
ZStack {
TabView() {
AccountView()
.tabItem {
Image(systemName: "person.crop.circle")
}
Text("Second")
.tabItem {
Image(systemName: "square.grid.2x2.fill")
}
}
// 4 - Observe full screen modal content appearing
if let view = fullScreenModal.content {
DimmedView {
view
}
.transition(.opacity)
.zIndex(.greatestFiniteMagnitude)
.edgesIgnoringSafeArea(.all)
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment