Last active
August 12, 2021 17:22
-
-
Save IsaAliev/e45a20c3d00bdab77edeff398e9ca371 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
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