Skip to content

Instantly share code, notes, and snippets.

@pofat
Created May 22, 2022 17:13
Show Gist options
  • Save pofat/e2541be0139ad132a016c4081d5cae79 to your computer and use it in GitHub Desktop.
Save pofat/e2541be0139ad132a016c4081d5cae79 to your computer and use it in GitHub Desktop.
struct Collapsable<Content: View>: View {
@State var collapsed: Bool = true
let content: () -> Content
init(@ViewBuilder content: @escapin () -> Content) {
self.content = content
}
var body: some View {
VStack {
if !collapsed {
content() // <--- Expand when body is called
}
Button(collapsed ? "↓ open" : "↑ close") {
visible.toggle()
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment