struct MyHtmlView: View {
let longHTML: String = "Lorem ipsum dolor sit amet, consectetur adipiscing elit. Sed est est, mattis vel ante sit amet, porttitor interdum dui. Nunc cursus lobortis ex, ut faucibus felis malesuada id. Vivamus in risus nec dolor ullamcorper tincidunt in at velit. Vestibulum nec mollis ipsum. Phasellus volutpat augue odio, ultricies accumsan magna eleifend tristique. Pellentesque habitant morbi tristique senectus et netus et malesuada fames ac turpis egestas. Pellentesque efficitur sem non dui ultricies sollicitudin eu eu sapien."
let shortHTML: String = "Lorem ipsum dolor sit amet, consectetur adipiscing elit. Sed est est, mattis vel ante sit amet, porttitor interdum dui. Nunc cursus lobortis ex, ut faucibus felis malesuada id."
@State private var isExpanded: Bool = false
var body: some View {
VStack {
RichText(html: isExpanded ? longHTML : shortHTML)
.lineHeight(120)
.colorScheme(.auto)
.transition(.easeOut)
.background(Color.red)
Button {
isExpanded.toggle()
} label: {
Text("Show more/less")
}
}
}
}
When the HTML changes from a long description to a short one the RichText frame's height remains equal to the bigger one calculated from the long description's height leaving a blank space underneath the RichText view
Considering this situation:
When the HTML changes from a long description to a short one the
RichText
frame's height remains equal to the bigger one calculated from the long description's height leaving a blank space underneath theRichText
view