Last active
August 12, 2021 17:40
-
-
Save IsaAliev/3392a8e55ca74d4e214c5c81f05be66c to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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