1

I was recently trying to implement list row resize using @ScaledMetric to add proper padding for different font sizes, but I stumbled upon an extremely weird issue: the row height changes massively when I add just 1 pixel of padding.

I thought this might be due to the complexity of my cells, so I reproduced the issue with a minimalist example:

struct ContentView: View {
    var body: some View {
        List {
            Section {
                Text("0px")
                    .background(.red)
                Text("1px")
                    .padding(.vertical, 1)
                    .background(.red)
                Text("2px")
                    .padding(.vertical, 2)
                    .background(.red)
                Text("3px")
                    .padding(.vertical, 3)
                    .background(.red)
                Text("4px")
                    .padding(.vertical, 4)
                    .background(.red)
                Text("5px")
                    .padding(.vertical, 5)
                    .background(.red)
                Text("6px")
                    .padding(.vertical, 6)
                    .background(.red)
                Text("7px")
                    .padding(.vertical, 7)
                    .background(.red)
            }
        }
        .listStyle(.insetGrouped)
    }
}

This code produces the following result:

enter image description here

Does anyone understand what’s going on? From 0 to 5 pixels of extra padding around the text, the cells do not increase in size. This seems reasonable, as there is still some empty space left.

Then, when 6 pixels of padding are added, the size suddenly shoots up—even though we could still fit the text with padding using the previous row height.

This seems like extremely unpredictable behaviour.

UPDATE

Above screenshot is reproducible on iOS 16 simulator running iOS 18.4. However, the behaviour is also reproducible on real devices. I was able to reproduce it on my iPhone 14 Pro Max (iOS 18.5) by adding another row with 8 pixel padding. Both case are with default font size. To ensure that you reproduce this on your device/simulator regardless of font size I suggest adding more rows, going all the way to 10 or 15 pixels in padding. If you do so, you will see the row height shooting up at some point.

2
  • I cannot reproduce on iOS 18.1 or iOS 18.4.1. What version of iOS are you running? Commented May 22 at 12:35
  • @Sweeper the example I included is reproducible on iOS 16 simulator running iOS 18.4. On my iPhone 14 Pro Max I am able to reproduce the same behaviour on default font size by adding another row with 8px padding. Commented May 22 at 13:27

1 Answer 1

3

This issue is being caused by the minimum default row height. Try setting to 0 to override the default:

List {
    Section {
        // as before
    }
}
.environment(\.defaultMinListRowHeight, 0) // 👈 here
.listStyle(.insetGrouped)

Screenshot

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.