I'm seeing related issues when using the Accessibility Inspector to change the Simulator's Dynamic Font Size for any SwiftUI iPhone iOS projects in Xcode 12.4
If the root NavigationView is left to the default navigationViewStyle (no modifiers) then I find the toolbars are broken across various views. Buttons appear/disappear randomly as you push/pop and its all a mess. However if I apply the '.navigationViewStyle(StackNavigationViewStyle())' modifier then it clears up all the toolbar problems across all views push onto the NavigationView.
The next issue: I've created a custom container View that hosts external content in either an HStack or VStack depending on the sizeCategory environment variable (Dynamic Font Size). This is a cut back version of it:
public struct DynamicStack<Content: View>: View
{
@Environment(\.sizeCategory) var sizeCategory: ContentSizeCategory
/// The external content to within this View.
var content: () -> Content
public init(@ViewBuilder content: @escaping () -> Content)
{
self.content = content
}
public var body: some View
{
Group
{
if (sizeCategory.isAccessibilityCategory)
{
VStack(content: content)
}
else
{
HStack(content: content)
}
}
}
}
If I host that in a NavigationView stack that is only 1-2 levels deep it works fine. That is when using the default navigationViewStyle (no modifiers).
However, once I create any further depth to the NavigationView stack (pushing more Views) then changing the font size in the Accessibility Inspector will cause a weird crash i.e;
libc++abi.dylib: terminating with uncaught exception of type NSException
*** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '<_TtGC7SwiftUI41StyleContextSplitViewNavigationControllerVS_19SidebarStyleContext_: 0x7feaa2030200> is pushing the same view controller instance (<_TtGC7SwiftUI41StyleContextSplitViewNavigationControllerVS_14NoStyleContext_: 0x7feaa1827e00>) more than once which is not supported and is most likely an error in the application : <REMOVED DEVELOPER KEY>'
terminating with uncaught exception of type NSException
CoreSimulator 732.18.6 - Device: iPhone SE (2nd generation) (5EA6E85C-3119-4FAE-BAB1-EECF5847FFE8) - Runtime: iOS 14.4 (18D46) - DeviceType: iPhone SE (2nd generation)
So, after finding this post, I re-applied the '.navigationViewStyle(StackNavigationViewStyle())' modifier. The crash no longer occurs, however the current View in the NavigationView will then multi-cycle re-refresh itself, seemingly adding multiple copies of itself to the stack. Sometimes it refreshes then auto-navigates back a page (pops off the stack), all depending on how deep in the NavigationView stack you are. All because of using the Accessibility Inspector tool window to change the font size? It's mental...
This all seems very broken to me.
Note: I now find I can't update to Xcode 12.5 (if you are going to say that fixes this issue) as our iMac is apparently a 'Late 2013' model (even though we bought it brand new from Apple website in 2015). In other words, we are not allowed to update to Big Sur - which is now required for all current & future Xcode 12.5+ updates and therefore are stuck on Xcode 12.4. Unfortunately I can't afford a new iMac.