SwiftUI - Force automatic title display mode in just one view

51 Views Asked by At

I have two views, both with their NavigationStack like this:

First View Code:

NavigationStack{

   VStack{

       NavigationLink{
         SecondView()
       }label:{
         \\some code here
       }

   }
   .navigationTitle("Title")
   .navigationBarTitleDisplayMode(.inline)
}

Second View Code:

NavigationStack{

   VStack{
     //some other code here
   }
   .navigationTitle("Title 2")
   .navigationBarTitleDisplayMode(.automatic)
}

Everything works fine but I'd love to force the SecondView title mode only to .automatic. As things are right now, when I navigate from the FirstView to the SecondView, the title mode of this last one is also set to ".inline".

I'd love to have the title set to ".inline" only for the FirstView.

Is there a way to achieve this in SwiftUI? Thanks.

1

There are 1 best solutions below

0
On BEST ANSWER

.automatic will use the display mode of the previous view on the stack. Only when there is no previous view does it default to .large when there is a title and .inline when there is no title. See documentation.

If you want the large title display mode then you need to explicitly use .large for your second view.