简体   繁体   中英

Navigationbar title is inline on pushed view, but was set to large

I want a large title in the navigationbar on a pushed view in SwiftUI and an inline title on the parent view.

When the parent navigation bar display mode is not set, it works: Working without display mode on parent

But when I set the display mode in the parent view to inline, the title on the second screen is inline, instead of large. You can drag the list and the title will stay large. (You can see a small example in the code below)

With display mode to inline on the parent, the child is also inline.

Here is a small example:

import SwiftUI

struct ContentView: View {
    var body: some View {
        NavigationView {
            NavigationLink(destination: DestinationView()) {
                Text("Next Screen")
            }
            .navigationBarTitle("Start screen", displayMode: .inline)
        }
    }
}

struct DestinationView: View {
    var body: some View {
        ScrollView {
            VStack{
                ForEach((1...10), id: \.self) {
                    Text("\($0)")
                }
            }
        }
        .navigationBarTitle("Second screen", displayMode: .large)
    }
}

There are several post with similar questions: https://www.reddit.com/r/iOSProgramming/comments/g2knmp/large_title_collapses_after_a_push_segue/ -> Same problem but with UIKit and we don't have prefersLargeTitles in SwiftUI.

Large title doesn't appear large -> Same problem with UIKit and marked as answered with preferesLargeTitles .

Navigation bar title stays inline in iOS 15 -> Here was a fix from apple side, but it was a back navigation

just place.navigationViewStyle(.stack) in NavigationView in ContentView()

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM