From 2efc0a17a94bb7de658bae055d222ef0f61ee989 Mon Sep 17 00:00:00 2001 From: Maurice Parker Date: Sun, 26 Jul 2020 15:31:32 -0500 Subject: [PATCH] Make Sidebar expansion state available to SidebarModel --- .../Shared/Sidebar/SidebarExpandedContainers.swift | 6 ++---- Multiplatform/Shared/Sidebar/SidebarModel.swift | 1 + Multiplatform/Shared/Sidebar/SidebarView.swift | 5 ++--- 3 files changed, 5 insertions(+), 7 deletions(-) diff --git a/Multiplatform/Shared/Sidebar/SidebarExpandedContainers.swift b/Multiplatform/Shared/Sidebar/SidebarExpandedContainers.swift index 8768a9a63..fcec7d03b 100644 --- a/Multiplatform/Shared/Sidebar/SidebarExpandedContainers.swift +++ b/Multiplatform/Shared/Sidebar/SidebarExpandedContainers.swift @@ -10,10 +10,9 @@ import SwiftUI import Combine import Account -final class SidebarExpandedContainers: ObservableObject { +struct SidebarExpandedContainers { - @Published var expandedTable = [ContainerIdentifier: Bool]() - var objectDidChange = PassthroughSubject() + var expandedTable = [ContainerIdentifier: Bool]() var data: Data { get { @@ -41,7 +40,6 @@ final class SidebarExpandedContainers: ObservableObject { } set(newValue) { expandedTable[containerID] = newValue - objectDidChange.send() } } diff --git a/Multiplatform/Shared/Sidebar/SidebarModel.swift b/Multiplatform/Shared/Sidebar/SidebarModel.swift index a427de45a..24d93c825 100644 --- a/Multiplatform/Shared/Sidebar/SidebarModel.swift +++ b/Multiplatform/Shared/Sidebar/SidebarModel.swift @@ -21,6 +21,7 @@ class SidebarModel: ObservableObject, UndoableCommandRunner { @Published var selectedFeedIdentifiers = Set() @Published var selectedFeedIdentifier: FeedIdentifier? = .none @Published var isReadFiltered = false + @Published var expandedContainers = SidebarExpandedContainers() weak var delegate: SidebarModelDelegate? diff --git a/Multiplatform/Shared/Sidebar/SidebarView.swift b/Multiplatform/Shared/Sidebar/SidebarView.swift index ec87a9797..f75d3a122 100644 --- a/Multiplatform/Shared/Sidebar/SidebarView.swift +++ b/Multiplatform/Shared/Sidebar/SidebarView.swift @@ -19,7 +19,6 @@ struct SidebarView: View { // I had to comment out SceneStorage because it blows up if used on macOS // @SceneStorage("expandedContainers") private var expandedContainerData = Data() - @StateObject private var expandedContainers = SidebarExpandedContainers() private let threshold: CGFloat = 80 @State private var previousScrollOffset: CGFloat = 0 @@ -142,10 +141,10 @@ struct SidebarView: View { var rows: some View { ForEach(sidebarItems) { sidebarItem in if let containerID = sidebarItem.containerID { - DisclosureGroup(isExpanded: $expandedContainers[containerID]) { + DisclosureGroup(isExpanded: $sidebarModel.expandedContainers[containerID]) { ForEach(sidebarItem.children) { sidebarItem in if let containerID = sidebarItem.containerID { - DisclosureGroup(isExpanded: $expandedContainers[containerID]) { + DisclosureGroup(isExpanded: $sidebarModel.expandedContainers[containerID]) { ForEach(sidebarItem.children) { sidebarItem in SidebarItemNavigation(sidebarItem: sidebarItem) }