I am repeatedly getting stuck on situations like this, where I have a List with extracted views, which use GeometryReader to layout their subviews as a proportion of the view itself, and they do not render properly. Here's an example, where the text is getting truncated. I am unsure why it is happening.
Here's a simplified version of the code:
Does this have to do with the fact that I haven't given the rows a height? I am assuming that Text elements take up the space required. Neither limitLimit nor layoutPriority is helping so far.
So what can I do to prevent the Text from getting truncated?
Here's a simplified version of the code:
Code Block import SwiftUI struct RatioTestView: View { var body: some View { List { ForEach(0..<100) { index in RatioSubView() .listRowInsets(EdgeInsets()) } } .listStyle(InsetGroupedListStyle()) .navigationTitle(Text("Long text")) } } struct RatioTestView_Previews: PreviewProvider { static var previews: some View { NavigationView { RatioTestView() } } } struct RatioSubView: View { var body: some View { GeometryReader { geometry in HStack(spacing: 0) { Text("Hello there! This is some really long text. And I can't figure out how to prevent this from getting truncated.") .lineLimit(Int.max) .layoutPriority(1) .frame(maxHeight: .infinity) .frame(width: geometry.size.width * 0.4) .background(Color.yellow) VStack(spacing: 0) { Color.red .frame(height: geometry.size.height * 0.2) Color.blue .frame(height: geometry.size.height * 0.4) Color.green .frame(height: geometry.size.height * 0.4) } .frame(width: geometry.size.width * 0.6) } } } }
Does this have to do with the fact that I haven't given the rows a height? I am assuming that Text elements take up the space required. Neither limitLimit nor layoutPriority is helping so far.
So what can I do to prevent the Text from getting truncated?