Reputation: 4176
For some reason, putting a GeometryReader
as an intermediary, kills geometry of its nested views if it's a List
"cell".
Example code:
struct SampleView: View {
var multilineText: some View {
Text(
"""
Some
Amazing
Multiline
Copy
"""
)
}
var body: some View {
List(1...5, id: \.self) { _ in
GeometryReader { _ in
self.multilineText
}
}
}
}
Without GeometryReader
(Expected) / Actual with GeometryReader
:
This example, obviously, is over-simplified, but there is a legitimate reason to measure geometry for a nested view I'm building.
This is on Xcode 11 beta 6. Should I go straight into reporting this as a bug, or it's something expected and workable around?
Upvotes: 8
Views: 2283
Reputation: 335
Add min row height for the list.
List(1...5, id: \.self) { _ in
GeometryReader { _ in
self.multilineText
}
}.environment(\.defaultMinListRowHeight, 100)
Upvotes: 2