Skip to content

Instantly share code, notes, and snippets.

@shanmugam105
Created April 3, 2024 14:00
Show Gist options
  • Save shanmugam105/0c7c36b820fe810405e1a2da99378ff8 to your computer and use it in GitHub Desktop.
Save shanmugam105/0c7c36b820fe810405e1a2da99378ff8 to your computer and use it in GitHub Desktop.
Wrapper for present alert in SwiftUI
extension View {
func present<Content: View>(_ isPresented: Binding<Bool>, content: () -> Content) -> some View {
Group {
if isPresented.wrappedValue {
ZStack {
self
content()
}
.frame(maxWidth: .infinity, maxHeight: .infinity)
} else {
self
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment