Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Any way to avoid SwiftUI GeometryReader preventing nested view to grow inside List?

Tags:

ios

swift

swiftui

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?

like image 894
rshev Avatar asked Aug 20 '19 01:08

rshev


1 Answers

Add min row height for the list.

List(1...5, id: \.self) { _ in
    GeometryReader { _ in
        self.multilineText
    }
}.environment(\.defaultMinListRowHeight, 100)
like image 146
Nilay Avatar answered Nov 10 '22 01:11

Nilay