Fix navigation view with dynamic items
This commit is contained in:
parent
8ec85b877f
commit
b5ee07485b
@ -1,6 +1,6 @@
|
|||||||
//
|
//
|
||||||
// AlertDialog.swift
|
// AlertDialog.swift
|
||||||
// Adwaita
|
// WinUI
|
||||||
//
|
//
|
||||||
// Created by david-swift on 12.11.24.
|
// Created by david-swift on 12.11.24.
|
||||||
//
|
//
|
||||||
@ -18,10 +18,12 @@ public struct ContentDialog: WinUIWidget {
|
|||||||
var title: String
|
var title: String
|
||||||
/// The body text.
|
/// The body text.
|
||||||
var body: Body
|
var body: Body
|
||||||
|
// swiftlint:disable large_tuple
|
||||||
/// The primary response.
|
/// The primary response.
|
||||||
var primary: (String, Bool, () -> Void)?
|
var primary: (String, Bool, () -> Void)?
|
||||||
/// The secondary response.
|
/// The secondary response.
|
||||||
var secondary: (String, Bool, () -> Void)?
|
var secondary: (String, Bool, () -> Void)?
|
||||||
|
// swiftlint:enable large_tuple
|
||||||
/// The close response.
|
/// The close response.
|
||||||
var close: (String, () -> Void)?
|
var close: (String, () -> Void)?
|
||||||
/// The child view.
|
/// The child view.
|
||||||
@ -39,7 +41,7 @@ public struct ContentDialog: WinUIWidget {
|
|||||||
child: AnyView,
|
child: AnyView,
|
||||||
id: String,
|
id: String,
|
||||||
title: String,
|
title: String,
|
||||||
@ViewBuilder body: () -> Body = { [] }
|
@ViewBuilder body: () -> Body = { [] }
|
||||||
) {
|
) {
|
||||||
self._visible = visible
|
self._visible = visible
|
||||||
self.child = child
|
self.child = child
|
||||||
|
@ -162,7 +162,7 @@ public struct NavigationView<Item>: WinUIWidget where Item: NavigationViewItem {
|
|||||||
}
|
}
|
||||||
view.selectionChanged.addHandler { _, args in
|
view.selectionChanged.addHandler { _, args in
|
||||||
let name = (args?.selectedItem as? WinUI.NavigationViewItem)?.name ?? items.first?.description ?? ""
|
let name = (args?.selectedItem as? WinUI.NavigationViewItem)?.name ?? items.first?.description ?? ""
|
||||||
if let item = items.first(where: { $0.description == name }) {
|
if let item = (storage.fields["items"] as? [Item])?.first(where: { $0.description == name }) {
|
||||||
if selectedItem != .custom(item: item) {
|
if selectedItem != .custom(item: item) {
|
||||||
selectedItem = .custom(item: item)
|
selectedItem = .custom(item: item)
|
||||||
}
|
}
|
||||||
@ -222,6 +222,7 @@ public struct NavigationView<Item>: WinUIWidget where Item: NavigationViewItem {
|
|||||||
.first { ($0 as? WinUI.NavigationViewItem)?.name as? String == name.description } as Any?
|
.first { ($0 as? WinUI.NavigationViewItem)?.name as? String == name.description } as Any?
|
||||||
}
|
}
|
||||||
navigationView.isBackEnabled = path.count > 1
|
navigationView.isBackEnabled = path.count > 1
|
||||||
|
storage.fields["items"] = items
|
||||||
storage.previousState = self
|
storage.previousState = self
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user