I have a SwiftUI view like this:
var body: some View {
VStack(alignment: .leading) {
Text(message)
.font(.light16)
.foregroundColor(.black)
.multilineTextAlignment(.leading)
.padding(.bottom, 8)
...
}
}
This message sometimes can be very large. I would like that in that cases, when the Text component is higher than 200px (for example), a expand/collapse button appears, so the user can read a shorter version of the message (200px) or the full message (its full height). Something like this:
var body: some View {
VStack(alignment: .leading) {
Text(message)
.font(.light16)
.foregroundColor(.black)
.multilineTextAlignment(.leading)
.padding(.bottom, 8)
Button {
self.isCollapsed = !self.isCollapsed
// expand or collapse the Text
} label: {
let title = self.isCollapsed ? "expand text" : "collapse text"
Text(title)
.font(.bold14)
.foregroundColor(Color.blue)
.multilineTextAlignment(.leading)
.padding(.bottom, 8)
}
}
...
}
I've used GeometryReader and proxy in other occasions but I don't know how to use it for this case. How could I get this functionality?