0

When I select an item in my NavigationSplitView, the menu does not dismiss.

I am using a encapsulated view that is used in the iPhone layout / before iOS 16 and I'm wondering if there is a command to dismiss the menu.

I would still like to keep the current behaviour for landscape iPad though since the menu there does not overlap the detail view:

@available (iOS 16.0, *)
struct SplitLibraryView: View {
    @StateObject var viewModel: SplitLibraryViewModel = SplitLibraryViewModel()
    var body: some View {
        NavigationSplitView(columnVisibility: $viewModel.visibility) {
            NavigationStack {
                LibraryView(viewModel: viewModel.libraryViewModel)
            }
        } detail: {
            switch viewModel.detailType {
            case .collections:
                CollectionsView(sharedWithMe: false)
            case .shared:
                CollectionsView(sharedWithMe: true)
            case .bookmarks:
                EmptyView()
            case .space(let id, let name):
                SpaceView(spaceId: id, spaceName: name)
            case .addSpace:
                EmptyView()
            }
        }
    }
}

@available (iOS 16.0, *)
class SplitLibraryViewModel: ObservableObject {
    @Published var detailType: LibraryMenuItemType = .collections
    @Published var libraryViewModel = LibraryViewModel(delegate: nil)
    @Published var visibility: NavigationSplitViewVisibility = .automatic
    init() {
        libraryViewModel.delegate = self
    }
}

@available (iOS 16.0, *)
extension SplitLibraryViewModel: LibraryViewDelegate {
    func profileLoaded(profile: Profile) {
        libraryViewModel.profile = profile
        Profile.me = profile
    }
    
    func itemSelected(item: HashableLibraryMenuItem) {
        self.detailType = item.type // Detail view is changed here
    }
}

I have tried calling /.dismiss upon selection but that doesn't work

is there a way to collapse the menu (for compact layouts) when the detail screen is updated?

Can a NavigationPath be used for the detail view?

Halpo
  • 2,982
  • 3
  • 25
  • 54

0 Answers0