2

There are a few posts regarding SwiftUI .inline not resetting to .largeTitle when navigation returns to the parent: For example: Navigation bar title stays inline in iOS 15 and Navigationbar title is inline on pushed view, but was set to large

While earlier posts seem to suggest this has been corrected, I'm running into the same problem, even in iOS 16, but I'm not using a < Back button, instead I'm using "Cancel" (and not show, "Save") on my DestinationView. My goal is to mimic Apple's practice of showing a modal view when adding data, but a show-style push on the navigation stack when viewing and editing existing data (e.g. Contacts app, Reminders app, Calendar app). The brief code below illustrates the problem without adding extra code to handle data updating (e.g. @EnviornmentObject).

When I run this in the Live Preview in Xcode 14.0.1, scheme set to iPhone 13 Pro, no problems. Click a NavLink, return from destination, and ContentView shows .large navigationBarTitle. BUT when I run in the simulator or on a 13 Pro device, returning to Home from a NavigationLink remains .inline unless I pull down on the list. If I switch to iPhone 14 Pro, the live preview looks fine, but the simulator shows a short of abrupt switch from inline back to large, not a smooth animation. Am I doing something wrong in the setup here or is there a bug in the implementation, noting that the behavior oddly holds to .inline on return home to ContentView, if I use this in either a simulator or device for iPhone 13 Pro. Thanks for guidance & insight!

enter image description here

struct ContentView: View {
    @State private var sheetIsPresented = false
    var items = ["Item1", "Item2", "Item3"]
    var body: some View {
        NavigationStack {
            List {
                ForEach(items, id: \.self) { item in
                    NavigationLink(item, destination: DestinationView(item: item))
                        .padding()
                }
            }
            .navigationBarTitle("Home", displayMode: .large)
            .listStyle(.plain)
            .toolbar {
                ToolbarItem(placement: .navigationBarTrailing) {
                    Button {
                        sheetIsPresented.toggle()
                    } label: {
                        Image(systemName: "plus")
                    }
                }
            }
        }
        .sheet(isPresented: $sheetIsPresented) {
            NavigationStack {
                DestinationView(item: "New!")
            }
        }
    }
}

struct DestinationView: View { var item: String @Environment(.dismiss) private var dismiss

var body: some View {
    List {
        Text(item)
    }
    .toolbar {
        ToolbarItem (placement: .navigationBarLeading) {
            Button("Cancel") {
                dismiss()
            }
        }
    }
    .listStyle(.plain)
    .navigationBarTitleDisplayMode(.inline)
    .navigationBarBackButtonHidden()
}

}

Gallaugher
  • 1,593
  • 16
  • 27

0 Answers0