Add support for complex navigation in NavigationView
This commit is contained in:
parent
adf4cfa8df
commit
9f545190a1
@ -31,36 +31,38 @@ public struct NavigationView<Item>: WinUIWidget where Item: NavigationViewItem {
|
||||
/// The label for the settings item.
|
||||
var settingsLabel: String?
|
||||
|
||||
/// The currently selected item.
|
||||
var selectedItem: Selection {
|
||||
/// The currently selected flat navigation item.
|
||||
var selectedItem: Selection? {
|
||||
get {
|
||||
if let last = path.last(
|
||||
where: { item in
|
||||
switch item {
|
||||
case .settings:
|
||||
return settings
|
||||
case let .custom(item):
|
||||
return items.contains(item)
|
||||
}
|
||||
if path.isEmpty, let first = items.first {
|
||||
path.append(.custom(item: first))
|
||||
}
|
||||
return path.last { component in
|
||||
switch component {
|
||||
case .settings:
|
||||
true
|
||||
case let .custom(item):
|
||||
items.contains(item)
|
||||
}
|
||||
) {
|
||||
last
|
||||
} else if let first = items.first {
|
||||
.custom(item: first)
|
||||
} else {
|
||||
.settings
|
||||
}
|
||||
}
|
||||
nonmutating set {
|
||||
path.append(newValue)
|
||||
if let newValue {
|
||||
path.append(newValue)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// The currently selected complex navigation item.
|
||||
var complexItem: Selection? {
|
||||
path.last
|
||||
}
|
||||
|
||||
/// The view's header.
|
||||
var header: AnyView? {
|
||||
if let settingsLabel {
|
||||
Grid {
|
||||
Text(selectedItem.description ?? settingsLabel)
|
||||
Text(complexItem?.description ?? settingsLabel)
|
||||
ModifierWrapper(
|
||||
view: CommandBar {
|
||||
primaryCommands
|
||||
@ -219,7 +221,7 @@ public struct NavigationView<Item>: WinUIWidget where Item: NavigationViewItem {
|
||||
navigationView.selectedItem = navigationView.menuItems
|
||||
.first { ($0 as? WinUI.NavigationViewItem)?.name as? String == name.description } as Any?
|
||||
}
|
||||
navigationView.isBackEnabled = !path.isEmpty
|
||||
navigationView.isBackEnabled = path.count > 1
|
||||
storage.previousState = self
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user