reports
reports copied to clipboard
FB19760681: TextField with axis: .vertical has invalid intrinsicContentSize
Submission Date
2025-08-19
Status
Open
Area
SwiftUI
Operating System Version
iOS 26
Type
Incorrect/Unexpected Behavior
Description
Hi I noticed when I use axis .vertical the intrinsicContentSize is invalid, it's 0,0. I know this renders as a UITextView in this case instead of a UITextField when its single line so probably has something to do with that. e.g.
@State var text = "Test"
TextField("", text: $text, axis: .vertical)
Incorrectly gives:
intrinsicContentSize (0.0, 0.0)
preferredContentSize (0.0, 0.0)
TextField(text: $text)
Correctly gives:
intrinsicContentSize (32.666666666666664, 22.0)
preferredContentSize (32.666666666666664, 22.0)
I've attached my test harness that uses a UIHostingController in a UIViewControllerRepresentable to read the sizes. Run it on iPhone 16 Simulator in Xcode 26 beta 6. Or current release Xcode with iOS 18.
I discovered it because I'm working on a UIViewController container view for SwiftUI content in a SwiftUI hierarchy.
import SwiftUI
struct ExpandingView: View {
@State var text = "Test"
var body: some View {
TextField("", text: $text, axis: .vertical) // intrinsicContentSize is bad
//TextField(text: $text)
}
}
struct WrapperHostingControllerRepresentable<Content: View>: UIViewControllerRepresentable {
@ViewBuilder var content: Content
func makeUIViewController(context: Context) -> MyHostingController<Content> {
let vc = MyHostingController(rootView: content)
vc.safeAreaRegions = []
vc.sizingOptions = [.preferredContentSize]
return vc
}
func updateUIViewController(_ uiViewController: MyHostingController<Content>, context: Context) {
uiViewController.rootView = content
}
func sizeThatFits(_ proposal: ProposedViewSize, uiViewController: MyHostingController<Content>, context: Context) -> CGSize? {
print("representable sizeThatFits")
let target = CGSize(
width: proposal.width ?? 0,
height: proposal.height ?? 0
)
var size = uiViewController.sizeThatFits(in: target)
print("sizeThatFits \(size)")
return size
}
}
class MyHostingController<Content: View>: UIHostingController<Content> {
override func viewDidLayoutSubviews() {
super.viewDidLayoutSubviews()
print("intrinsicContentSize \(view.intrinsicContentSize)")
print("preferredContentSize \(preferredContentSize)")
}
}
struct ContentView: View {
var body: some View {
WrapperHostingControllerRepresentable {
ExpandingView()
}
.border(Color.red)
}
}
Keywords
No response
Prerequisites
- [x] The title follows the format
FB<number>: <title> - [x] I will keep this issue updated with Apple's responses