Text clips during animated change

In the following sample, tapping the 'Expand' button causes the text '39' to clip as it resizes in transition to '40'. I'd like for the text to only take up the space that it requires, but without clipping as it animates between values.



Disabling animations for the label isn't an option, as the real use case here involves the animation of other modifiers to the view (e.g. offset).


import SwiftUI


struct TextClipping: View {
    @State var expanded = false


    var body: some View {
        VStack(spacing: 16) {
            Text(expanded ? "40" : "39")
                .font(.title)
                .foregroundColor(.blue)


            Button(action: {
                withAnimation {
                    self.expanded.toggle()
                }
            }, label: {
                Text(expanded ? "Contract" : "Expand")
                    .animation(nil) // Not an option for text above
            })
        }
    }
}


struct TextClipping_Previews: PreviewProvider {
    static var previews: some View {
        TextClipping()
    }
}



Any ideas for how I might allow the text of the label to change fluidly, without clipping?


[Filed as FB7383199]

Accepted Reply

Update: resolved the issue by applying:


.minimumScaleFactor(0.1)


to the Text.

Replies

Update: resolved the issue by applying:


.minimumScaleFactor(0.1)


to the Text.