HomeiOS Developmentios - SwiftUI: NavigationSplitView title bar points

ios – SwiftUI: NavigationSplitView title bar points


I’ve filed this as a bug with Apple (FB12119822) since I’m pretty sure there’s nothing mistaken with my code, however posting right here for posterity and in case other people have discovered a workaround.

When navigating between checklist and element sections in a NavigationSplitView, the title bar unexpectedly jumps between inline and huge show modes. In some situations, the title seems to be empty till the navigation segue is full, after which it all of the sudden renders in a big show mode, pushing view content material down.

Steps to breed

  1. Create a NavigationSplitView with a sidebar of navigable Record objects and a element view akin to the chosen merchandise with a navigation bar title
  2. Navigate into the element view

Anticipated end result

The navigation segue animates the origin title into the “Again” button of the navigation bar, and concurrently animates the vacation spot’s navigation bar title right into a default (giant) show mode

Precise end result

The navigation segue animates the origin title into the “Again” button of the navigation bar, however no vacation spot title is displayed. When the segue completes, the ”Again” button textual content is changed with the default textual content (“Again”) and the vacation spot title all of the sudden seems. (Display screen recording)

Further observations

The above behaviour is exhibited when the NavigationSplitView’s Record has a choice argument. When as a substitute the navigationDestination modifier is utilized, the title bar of each the origin checklist and vacation spot element view is impacted. (Display screen recording)

Code samples

Record(choice:)

import SwiftUI

fileprivate struct Merchandise: Identifiable, Hashable {
    let id = UUID()
}

fileprivate let objects = (0...10).map { _ in Merchandise() }

struct ListWithSelectionTitleBarJumpExample: View {
    @State var selectedItem: UUID?

    var physique: some View {
        NavigationSplitView {
            Record(choice: $selectedItem) {
                Part {
                    ForEach(objects) { merchandise in
                        Textual content(merchandise.id.uuidString)
                            .tag(merchandise.id)
                    }
                } header: {
                    Textual content("Navigable rows")
                }
            }
            .navigationTitle("Navigation Title Soar")
        } element: {
            if let selectedItem,
                 let merchandise = objects.first(the place: { $0.id == selectedItem }) {
                Textual content(merchandise.id.uuidString)
                    .navigationTitle("Element View")
            } else {
                Textual content("No choice")
            }
        }
    }
}

struct ListWithSelectionTitleBarJumpExample_Previews: PreviewProvider {
    static var previews: some View {
        ListWithSelectionTitleBarJumpExample()
    }
}

Record.navigationDestination

import SwiftUI

fileprivate struct Merchandise: Identifiable, Hashable {
    let id = UUID()
}

fileprivate let objects = (0...10).map { _ in Merchandise() }

struct ListWithNavigationDestinationTitleBarJumpExample: View {
    var physique: some View {
        NavigationSplitView {
            Record {
                Part {
                    ForEach(objects) { merchandise in
                        NavigationLink(worth: merchandise) {
                            Textual content(merchandise.id.uuidString)
                        }
                    }
                } header: {
                    Textual content("Navigable rows")
                }
            }
            .navigationTitle("Navigation Title Soar")
            .navigationDestination(for: Merchandise.self) { worth in
                Textual content(worth.id.uuidString)
                    .navigationTitle("Element View")
            }
        } element: {
            Textual content("No choice")
        }
    }
}

struct ListWithNavigationDestinationTitleBarJumpExample_Previews: PreviewProvider {
    static var previews: some View {
        ListWithNavigationDestinationTitleBarJumpExample()
    }
}

RELATED ARTICLES

LEAVE A REPLY

Please enter your comment!
Please enter your name here

Most Popular

Recent Comments