lineLimit(_:reservesSpace:) does not take into account custom line heights

Originator:cameroncooke
Number:rdar://FB13482808 Date Originated:21/12/2023
Status:Open Resolved:
Product:SwiftUI Product Version:iOS 17.2
Classification: Reproducible:Yes
 
When using TextField with the `lineSpacing(_:)` and `lineLimit(_:reservesSpace:)` modifiers and setting the `reservesSpace` argument to `true` the height of the vertical TextField does not calculate correctly.

In the following example, the code snippet has the number of lines set to `5` and the `reservesSpace` argument is set to `true`. The expected behaviour here would be that the TextField would be sized to accommodate 5 lines of text. Instead, the TextFIeld only accommodates 2.5 lines of text.

```
TextField("", text: $text, axis: .vertical)
    .font(.headline)
    .lineSpacing(25)
    .lineLimit(5, reservesSpace: true)
    .textFieldStyle(.roundedBorder)
```

It’s also worth noting which can be seen in the video, that the initial text insertion cursor is massively oversized until you start typing.

Attached is a playground file demonstrating the issue and a video recording.

Comments


Please note: Reports posted here will not necessarily be seen by Apple. All problems should be submitted at bugreport.apple.com before they are posted here. Please only post information for Radars that you have filed yourself, and please do not include Apple confidential information in your posts. Thank you!