Change to use a view instead of a function for the navigation wrapper

This commit is contained in:
Maurice Parker 2020-07-15 15:25:41 -05:00
parent 367bd90ec9
commit f32b0bfdc3
1 changed files with 23 additions and 16 deletions

View File

@ -71,13 +71,13 @@ struct SidebarView: View {
if let containerID = sidebarItem.containerID { if let containerID = sidebarItem.containerID {
DisclosureGroup(isExpanded: $expandedContainers[containerID]) { DisclosureGroup(isExpanded: $expandedContainers[containerID]) {
ForEach(sidebarItem.children) { sidebarItem in ForEach(sidebarItem.children) { sidebarItem in
buildSidebarItemNavigation(sidebarItem) SidebarItemNavigation(sidebarItem: sidebarItem)
} }
} label: { } label: {
buildSidebarItemNavigation(sidebarItem) SidebarItemNavigation(sidebarItem: sidebarItem)
} }
} else { } else {
buildSidebarItemNavigation(sidebarItem) SidebarItemNavigation(sidebarItem: sidebarItem)
} }
} }
} label: { } label: {
@ -91,11 +91,16 @@ struct SidebarView: View {
} }
} }
func buildSidebarItemNavigation(_ sidebarItem: SidebarItem) -> some View { struct SidebarItemNavigation: View {
@EnvironmentObject private var sidebarModel: SidebarModel
var sidebarItem: SidebarItem
@ViewBuilder var body: some View {
#if os(macOS) #if os(macOS)
return SidebarItemView(sidebarItem: sidebarItem).tag(sidebarItem.feed!.feedID!) SidebarItemView(sidebarItem: sidebarItem).tag(sidebarItem.feed!.feedID!)
#else #else
return ZStack { ZStack {
SidebarItemView(sidebarItem: sidebarItem) SidebarItemView(sidebarItem: sidebarItem)
NavigationLink(destination: TimelineContainerView(feeds: sidebarModel.selectedFeeds), NavigationLink(destination: TimelineContainerView(feeds: sidebarModel.selectedFeeds),
tag: sidebarItem.feed!.feedID!, tag: sidebarItem.feed!.feedID!,
@ -107,3 +112,5 @@ struct SidebarView: View {
} }
} }
}