fix(reader): force menu rebuild so toggle checkmarks reflect state
Viewer Insights (and likely Subscribed/Full Width, same mechanism) kept showing the pre-toggle checkmark in the overflow menu until the whole view was torn down and rebuilt (navigate away and back) - SwiftUI's macOS Menu doesn't reliably re-evaluate a Toggle's checkmark against updated @Observable state on its own. Keying the Menu's .id() to every toggle-backed state it displays forces a fresh rebuild whenever any of them change.
This commit is contained in:
@@ -127,6 +127,13 @@ struct DocumentReaderView: View {
|
|||||||
} label: {
|
} label: {
|
||||||
Image(systemName: "ellipsis.circle")
|
Image(systemName: "ellipsis.circle")
|
||||||
}
|
}
|
||||||
|
// SwiftUI's macOS `Menu` doesn't reliably re-evaluate a
|
||||||
|
// `Toggle`'s checkmark against updated @Observable state on
|
||||||
|
// its own — without a fresh `.id()` per state combination,
|
||||||
|
// toggling Subscribed/Viewer Insights/Full Width kept
|
||||||
|
// showing the pre-toggle checkmark until the whole view was
|
||||||
|
// torn down and rebuilt (e.g. navigating away and back).
|
||||||
|
.id(menuIdentity)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
.task { await viewModel.loadFullContent() }
|
.task { await viewModel.loadFullContent() }
|
||||||
@@ -205,6 +212,19 @@ struct DocumentReaderView: View {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Every toggle-backed piece of state shown as a checkmark inside
|
||||||
|
/// `menuContent` — see the `.id()` comment on the `Menu` above.
|
||||||
|
private var menuIdentity: String {
|
||||||
|
[
|
||||||
|
starStore.isStarred(documentId: viewModel.documentId),
|
||||||
|
viewModel.isSubscribed,
|
||||||
|
viewModel.isPinned,
|
||||||
|
viewModel.isInsightsEnabled ?? false,
|
||||||
|
viewModel.isFullWidth,
|
||||||
|
viewModel.isEditing
|
||||||
|
].map(String.init).joined(separator: "-")
|
||||||
|
}
|
||||||
|
|
||||||
@ViewBuilder
|
@ViewBuilder
|
||||||
private var viewerAvatars: some View {
|
private var viewerAvatars: some View {
|
||||||
if !viewModel.viewers.isEmpty {
|
if !viewModel.viewers.isEmpty {
|
||||||
|
|||||||
Reference in New Issue
Block a user