Skip to content

Instantly share code, notes, and snippets.

@IsaAliev
Last active August 12, 2021 17:22
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/e45a20c3d00bdab77edeff398e9ca371 to your computer and use it in GitHub Desktop.
Save IsaAliev/e45a20c3d00bdab77edeff398e9ca371 to your computer and use it in GitHub Desktop.
struct AccountView: View {
@State var showsModal: Bool = false
var body: some View {
ZStack {
Button("Show modal") {
withAnimation {
showsModal = true
}
}
if showsModal {
DimmedView {
ModalView(isShowing: $showsModal)
}
.transition(.opacity)
.zIndex(.greatestFiniteMagnitude)
}
}
}
}
struct DimmedView<T: View>: View {
let content: () -> T
var body: some View {
ZStack {
DimmingView()
content()
}
}
}
struct DimmingView: View {
var body: some View {
Rectangle()
.frame(maxWidth: .infinity, maxHeight: .infinity)
.background(Color.black)
.opacity(0.3)
}
}
struct ModalView: View {
@Binding var isShowing: Bool
var body: some View {
VStack {
Text("This is modal view")
.padding()
Button("Close") {
withAnimation {
isShowing = false
}
}.padding()
}
.background(Color.white)
.cornerRadius(10)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment