Skip to content

Instantly share code, notes, and snippets.

@laevandus
Created June 21, 2023 08:35
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save laevandus/0b28af7186b7575d9cd74c829d864eec to your computer and use it in GitHub Desktop.
Save laevandus/0b28af7186b7575d9cd74c829d864eec to your computer and use it in GitHub Desktop.
struct CollapsibleView<Label, Content>: View where Label: View, Content: View {
@State private var isSecondaryViewVisible = false
@ViewBuilder let label: () -> Label
@ViewBuilder let content: () -> Content
var body: some View {
Group {
Button(action: { isSecondaryViewVisible.toggle() }, label: label)
.buttonStyle(.plain)
if isSecondaryViewVisible {
content()
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment