From f32b0bfdc365d3af61c5e06f33ce12398f8d06d0 Mon Sep 17 00:00:00 2001 From: Maurice Parker Date: Wed, 15 Jul 2020 15:25:41 -0500 Subject: [PATCH] Change to use a view instead of a function for the navigation wrapper --- .../Shared/Sidebar/SidebarView.swift | 39 +++++++++++-------- 1 file changed, 23 insertions(+), 16 deletions(-) diff --git a/Multiplatform/Shared/Sidebar/SidebarView.swift b/Multiplatform/Shared/Sidebar/SidebarView.swift index cbcd3cebc..f7c2fa2b9 100644 --- a/Multiplatform/Shared/Sidebar/SidebarView.swift +++ b/Multiplatform/Shared/Sidebar/SidebarView.swift @@ -71,13 +71,13 @@ struct SidebarView: View { if let containerID = sidebarItem.containerID { DisclosureGroup(isExpanded: $expandedContainers[containerID]) { ForEach(sidebarItem.children) { sidebarItem in - buildSidebarItemNavigation(sidebarItem) + SidebarItemNavigation(sidebarItem: sidebarItem) } } label: { - buildSidebarItemNavigation(sidebarItem) + SidebarItemNavigation(sidebarItem: sidebarItem) } } else { - buildSidebarItemNavigation(sidebarItem) + SidebarItemNavigation(sidebarItem: sidebarItem) } } } label: { @@ -90,20 +90,27 @@ struct SidebarView: View { } } } - - func buildSidebarItemNavigation(_ sidebarItem: SidebarItem) -> some View { - #if os(macOS) - return SidebarItemView(sidebarItem: sidebarItem).tag(sidebarItem.feed!.feedID!) - #else - return ZStack { - SidebarItemView(sidebarItem: sidebarItem) - NavigationLink(destination: TimelineContainerView(feeds: sidebarModel.selectedFeeds), - tag: sidebarItem.feed!.feedID!, - selection: $sidebarModel.selectedFeedIdentifier) { - EmptyView() - }.buttonStyle(PlainButtonStyle()) + + struct SidebarItemNavigation: View { + + @EnvironmentObject private var sidebarModel: SidebarModel + var sidebarItem: SidebarItem + + @ViewBuilder var body: some View { + #if os(macOS) + SidebarItemView(sidebarItem: sidebarItem).tag(sidebarItem.feed!.feedID!) + #else + ZStack { + SidebarItemView(sidebarItem: sidebarItem) + NavigationLink(destination: TimelineContainerView(feeds: sidebarModel.selectedFeeds), + tag: sidebarItem.feed!.feedID!, + selection: $sidebarModel.selectedFeedIdentifier) { + EmptyView() + }.buttonStyle(PlainButtonStyle()) + } + #endif } - #endif + } }