I'm trying to build a view that has Text
within a VStack
. I'd like the VStack
to fill the full width of the screen and I'd like the Text
within it to do the same. As far as I can tell the code for that would be as follows:
import SwiftUI
struct Test: View {
@State private var text = "Hello, World!"
var body: some View {
VStack {
Text(text)
.frame(maxWidth: .infinity)
.animation(.default)
Button(action: {
self.text = (self.text == "Text") ? "Hello, World!" : "Text"
}) {
Text("Toggle")
}
}
.frame(maxWidth: .infinity)
}
}
struct Test_Previews: PreviewProvider {
static var previews: some View {
Test()
}
}
When I check preview and hover over the text and the stack it shows exactly what I would expect, the Text
is full width. However, when I run the app and debug the view hierarchy, it shows that the Text
frame has been resized to fit the text. While typically I wouldn't mind this, it results in an animation showing ellipses when the text changes to longer copy. Is it possible to stop Text
from sizing to fit the copy?