From b5ee07485b5f1a3beae715f78a46316d269a359e Mon Sep 17 00:00:00 2001 From: david-swift Date: Mon, 18 Nov 2024 20:08:53 +0100 Subject: [PATCH] Fix navigation view with dynamic items --- Sources/Core/View/ContentDialog.swift | 6 ++++-- Sources/Core/View/NavigationView.swift | 3 ++- 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/Sources/Core/View/ContentDialog.swift b/Sources/Core/View/ContentDialog.swift index ea2d765..0b20ee3 100644 --- a/Sources/Core/View/ContentDialog.swift +++ b/Sources/Core/View/ContentDialog.swift @@ -1,6 +1,6 @@ // // AlertDialog.swift -// Adwaita +// WinUI // // Created by david-swift on 12.11.24. // @@ -18,10 +18,12 @@ public struct ContentDialog: WinUIWidget { var title: String /// The body text. var body: Body + // swiftlint:disable large_tuple /// The primary response. var primary: (String, Bool, () -> Void)? /// The secondary response. var secondary: (String, Bool, () -> Void)? + // swiftlint:enable large_tuple /// The close response. var close: (String, () -> Void)? /// The child view. @@ -39,7 +41,7 @@ public struct ContentDialog: WinUIWidget { child: AnyView, id: String, title: String, - @ViewBuilder body: () -> Body = { [] } + @ViewBuilder body: () -> Body = { [] } ) { self._visible = visible self.child = child diff --git a/Sources/Core/View/NavigationView.swift b/Sources/Core/View/NavigationView.swift index e7cc6b7..5d4c108 100644 --- a/Sources/Core/View/NavigationView.swift +++ b/Sources/Core/View/NavigationView.swift @@ -162,7 +162,7 @@ public struct NavigationView: WinUIWidget where Item: NavigationViewItem { } view.selectionChanged.addHandler { _, args in 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) { selectedItem = .custom(item: item) } @@ -222,6 +222,7 @@ public struct NavigationView: WinUIWidget where Item: NavigationViewItem { .first { ($0 as? WinUI.NavigationViewItem)?.name as? String == name.description } as Any? } navigationView.isBackEnabled = path.count > 1 + storage.fields["items"] = items storage.previousState = self }