Created
May 22, 2022 17:13
-
-
Save pofat/e2541be0139ad132a016c4081d5cae79 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 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