ViewThatFits and Text Truncation

I'm using ViewThatFits to handle different screen sizes as well as the orientation of the phone. Essentially, I have a smaller view that should only be used in portrait mode on the phone and a larger view that should be used in every other instance.

The issue is that both of those views have a Text view that is bound to a String within a SwiftData model.

If the String is too long the ViewThatFits considers that when choosing the appropriate subview. This results in a list of items where most items use one view while one or more may use the other view.

It would be great if there was a modifier that could be applied to the Text view that resulted in the ViewThatFits ignoring it when determining the appropriate subview.

Until such a modifier is available, has anyone come up with creative ways around this?

I found a work around although I still think there maybe more appropriate work arounds. I still think there is a need for a modifier to allow Text bound to long Strings, for example, to be ignored by ViewThatFits when evaluating potential subviews.

The work around that I'm using is the following:

ViewThatFits {
    // available on all platforms.
    VStack {
    }

    if(UIDevice.current.userInterfaceIdiom == .phone) {
        // iPhone only option.
        VStack {
        }
    }
}

Using this approach the smaller view is only used on iPhone in portrait mode and the other view is used on all other platforms. Without this, the smaller view in some cases was used on iPad mini when the Text view was bound to a long String.

It doesn't completely solve the issue as the wrong view is still sometimes chosen in landscape on the iPhone, but at least that issue is isolated only to the iPhone. Users on the iPad etc. will always see the wider view.

If you have a better solution to avoid long a String within a Text view from impacting ViewThatFits, please let me know.

ViewThatFits and Text Truncation
 
 
Q