ViewThatFits is a great way to handle large type and resizability. I wonder what are the performance considerations here? What are common pitfalls using it?
I appreciate any tip or thing to keep in mind. ✌️
The performance considerations really depend on your specific use case, especially if the views you're asking ViewThatFits to choose between are complex, since you're effectively initializing and measuring each candidate view and all of its children, and this happens on every layout pass.
For resizability, the best way to react to changes in size is by tracking size class changes for overall window size, or onGeometryChange for tracking the size of individual views. The nice thing about this is that it gives you more control over the thresholds at which the decision of which view to display happens.
Instead of making a conditional view decision on every frame of a resize action, you could try defining "break points" for your layout. For instance, you might code up some logic where when the parent view's width moves between certain ranges, you set a state variable that specifies which view to show. onGeometryChange's action closure only fires when the value returned by its transform closure changes, so this allows you to limit the frequency of updates to the specific transition points that matter to you, instead of updating on every frame.
That being said, ViewThatFits might be just fine for your use case. Ultimately, the best way to know if you're running into any performance issues is to use the SwiftUI instrument in Instruments to look at how much work is happening as you're resizing.