adjusting navigationTitle based on dynamic type size

I've found myself chasing my tail trying to programmatically adjust my .navigationTitle in SwiftUI so it doesn't get truncated given various dynamic type classes mixed with various device widths... Any guidance here on how to think about adjusting Ul copy based on AX type size constraints?

Answered by Frameworks Engineer in 891299022

Is this an iOS app?

I wouldn't expect navigation titles to get much larger with Dynamic Type on iOS, since the user can press and hold to access the Large Content Viewer. This WWDC session is a few years old but talks about relevant and helpful APIs regarding Large Content Viewer: https://developer.apple.com/videos/play/wwdc2019/261/

Looking at a few first party apps like Messages or Settings, the navigation title only grows for a few text sizes past 100% but then caps out. This is the behavior I'd recommend for your UI.

Otherwise please feel free to share UI screenshots if it helps the discussion.

Is this an iOS app?

I wouldn't expect navigation titles to get much larger with Dynamic Type on iOS, since the user can press and hold to access the Large Content Viewer. This WWDC session is a few years old but talks about relevant and helpful APIs regarding Large Content Viewer: https://developer.apple.com/videos/play/wwdc2019/261/

Looking at a few first party apps like Messages or Settings, the navigation title only grows for a few text sizes past 100% but then caps out. This is the behavior I'd recommend for your UI.

Otherwise please feel free to share UI screenshots if it helps the discussion.

Thank you, I will review that session. Yes, this is on iOS. In my app, the SwiftUI navigationTitle was getting truncated at larger sizes.

My solve was to shorten it, and add in a subtitle at largest sizes to still convey meaning.

private func navigationTitleAbridged(for title: String) -> String {
    if dynamicTypeSize >= .accessibility2 { return fullSqueeze(title) }
    if dynamicTypeSize >= .xxxLarge { return halfSqueeze(title) }
    return title
}

Your solution is really clever (and looks good too) but yeah I understand the "chasing your tail" aspect.

I have a feeling we can do better here, if you wouldn't mind submitting feedback for this as well.

Thanks for your guidance and feedback on this, I really appreciate it! The tail chasing ensued around trying to smooth out edge cases (i.e. a truncation on iPhone SE), but fix one break another. So I left it alone at generally better than where it started.

FB23039158

adjusting navigationTitle based on dynamic type size
 
 
Q