Fix navigation view with dynamic items
Some checks failed
SwiftLint / SwiftLint (push) Successful in 5s
Deploy Docs / publish (push) Failing after 26m44s

This commit is contained in:
david-swift 2024-11-18 20:08:53 +01:00
parent 8ec85b877f
commit b5ee07485b
2 changed files with 6 additions and 3 deletions

View File

@ -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

View File

@ -162,7 +162,7 @@ public struct NavigationView<Item>: 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<Item>: 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
}