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:
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.

