SwiftUI Dynamic Type Change with NavigationView pushes extra view controllers

This feels so simple that we must be doing something wrong.

When we change the font-size in the accessibility inspector, in the worst-case, we get a crash. In the best case, it pushes a new view controller on to the stack.

This was the simplest example we had:

Code Block swift
struct Fruit: Identifiable, Hashable {
  var id: String
}
struct ContentView: View {
  @State var fruit = [Fruit(id: "Apples"), Fruit(id: "Cherries"), Fruit(id: "Grapes")]
   
  var body: some View {
    NavigationView {
      List {
        ForEach(fruit) { item in
          NavigationLink(destination: Text("Hello World")) {
            Text(item.id)
          }
        }
      }.navigationTitle("Fruit")
    }.navigationViewStyle(StackNavigationViewStyle())
  }
}


If we load this up, then select one of the fruit to push on the detail page, when we change the font size in the accessibility inspector, it pushes on the DetailView again so that we have three view controllers in the stack.

Originally, we had three levels instead of two and we weren't setting the navigationViewStyle. In this case, it defaulted to a DoubleColumn style and crashed trying to push on the same view controller instance.

The apple sample code we tested also had this issue.

Tested on Xcode 12.4 on both simulators and devices.
Have you already sent a feedback to Apple?
You may need to attach sample project in addition to detailed description about steps to reproduce.
Not yet - it seemed too simple and broken that we wanted to sanity check we weren't being foolish first 🙃

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.

Hi all,

If you are able to file these using Feedback Assistant, please let me know with the Feedback ID number. Thanks in advance!

Does anyone know if a feedback has been sent about this? I'm still seeing it in Xcode (12.5.1) and on simulator (14.5) and devices (14.7.1). Thanks in advance.

SwiftUI Dynamic Type Change with NavigationView pushes extra view controllers
 
 
Q