Skip to content

Commit

Permalink
Sidebar: Replace DisclosureGroup with custom view
Browse files Browse the repository at this point in the history
  • Loading branch information
Dimillian committed May 15, 2021
1 parent 8701030 commit a95b130
Show file tree
Hide file tree
Showing 3 changed files with 50 additions and 21 deletions.
8 changes: 6 additions & 2 deletions RedditOs.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@
69EACF2524B73DF400303A16 /* SubredditViewModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = 69EACF2424B73DF400303A16 /* SubredditViewModel.swift */; };
69F74E9324DAE65100E58BD8 /* AwardView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 69F74E9224DAE65100E58BD8 /* AwardView.swift */; };
69F74E9624DB0B7300E58BD8 /* GlobalSearchPopoverView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 69F74E9524DB0B7300E58BD8 /* GlobalSearchPopoverView.swift */; };
9F19B57A26505DCF00FBEEDA /* SidebarMultiView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 9F19B57926505DCF00FBEEDA /* SidebarMultiView.swift */; };
9F4812CC264FC8DB007A719D /* SearchMainContentView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 9F4812CB264FC8DB007A719D /* SearchMainContentView.swift */; };
/* End PBXBuildFile section */

Expand Down Expand Up @@ -121,6 +122,7 @@
69EACF2424B73DF400303A16 /* SubredditViewModel.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SubredditViewModel.swift; sourceTree = "<group>"; };
69F74E9224DAE65100E58BD8 /* AwardView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AwardView.swift; sourceTree = "<group>"; };
69F74E9524DB0B7300E58BD8 /* GlobalSearchPopoverView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = GlobalSearchPopoverView.swift; sourceTree = "<group>"; };
9F19B57926505DCF00FBEEDA /* SidebarMultiView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SidebarMultiView.swift; sourceTree = "<group>"; };
9F4812CB264FC8DB007A719D /* SearchMainContentView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SearchMainContentView.swift; sourceTree = "<group>"; };
/* End PBXFileReference section */

Expand Down Expand Up @@ -338,6 +340,7 @@
children = (
69EACF1224B668F200303A16 /* SidebarView.swift */,
694C634E24C0AA6D0017897D /* SidebarSubredditRow.swift */,
9F19B57926505DCF00FBEEDA /* SidebarMultiView.swift */,
);
path = Sidebar;
sourceTree = "<group>";
Expand Down Expand Up @@ -470,6 +473,7 @@
693F85D424D0715000224ADB /* ToolbarSearchBar.swift in Sources */,
69EACF1524B6F1E200303A16 /* SubredditPostsListView.swift in Sources */,
697E324D24E3F2900006F00F /* SharingPicker.swift in Sources */,
9F19B57A26505DCF00FBEEDA /* SidebarMultiView.swift in Sources */,
692F237624CB3A7B006C9D40 /* SavedPostsListView.swift in Sources */,
6924D53E24CD94B0005487CA /* UserViewModel.swift in Sources */,
69222AA724CD6D6C009F31B4 /* SubmittedPostsListView.swift in Sources */,
Expand Down Expand Up @@ -645,7 +649,7 @@
"@executable_path/../Frameworks",
);
MACOSX_DEPLOYMENT_TARGET = 11.0;
MARKETING_VERSION = 0.4.2;
MARKETING_VERSION = 0.4.3;
PRODUCT_BUNDLE_IDENTIFIER = com.thomasricouard.curiosity;
PRODUCT_NAME = Curiosity;
SWIFT_VERSION = 5.0;
Expand All @@ -672,7 +676,7 @@
"@executable_path/../Frameworks",
);
MACOSX_DEPLOYMENT_TARGET = 11.0;
MARKETING_VERSION = 0.4.2;
MARKETING_VERSION = 0.4.3;
PRODUCT_BUNDLE_IDENTIFIER = com.thomasricouard.curiosity;
PRODUCT_NAME = Curiosity;
SWIFT_VERSION = 5.0;
Expand Down
38 changes: 38 additions & 0 deletions RedditOs/Features/Sidebar/SidebarMultiView.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
import SwiftUI
import Backend
import UI


struct SidebarMultiView: View {
@State private var isExpanded = false

let multi: Multi

var body: some View {
HStack {
Button(action: {
isExpanded.toggle()
}, label: {
Image(systemName: isExpanded ? "chevron.down" : "chevron.forward")
})
.buttonStyle(BorderlessButtonStyle())
NavigationLink(destination:
SubredditPostsListView(name: multi.subredditsAsName,
customTitle: multi.displayName)
.equatable()) {
Text(multi.displayName)
}
}
if isExpanded {
ForEach(multi.subreddits) { subreddit in
HStack {
NavigationLink(destination: SubredditPostsListView(name: subreddit.name)
.equatable()) {
Text(subreddit.name)
}
.padding(.leading, 8)
}
}
}
}
}
25 changes: 6 additions & 19 deletions RedditOs/Features/Sidebar/SidebarView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@

import SwiftUI
import Backend
import UI

struct SidebarView: View {
@EnvironmentObject private var uiState: UIState
Expand All @@ -25,12 +26,11 @@ struct SidebarView: View {
subscriptionSection
multiSection
}
.animation(nil)
.listStyle(SidebarListStyle())
.frame(minWidth: 200, idealWidth: 200, maxWidth: 200, maxHeight: .infinity)
.onHover { hovered in
.whenHovered({ hovered in
isHovered = hovered
}
})
.toolbar {
ToolbarItem(placement: .navigation) {
Button(action: toggleSidebar, label: {
Expand Down Expand Up @@ -82,7 +82,7 @@ struct SidebarView: View {
}

private var mainSection: some View {
Section {
Section(header: Text("Home")) {
NavigationLink(destination: SearchMainContentView(),
isActive: uiState.isSearchActive,
label: {
Expand Down Expand Up @@ -182,28 +182,15 @@ struct SidebarView: View {
if currentUser.user != nil && !currentUser.multi.isEmpty {
Section(header: Text("Multireddits")) {
ForEach(currentUser.multi) { multi in
DisclosureGroup {
ForEach(multi.subreddits) { subreddit in
NavigationLink(destination: SubredditPostsListView(name: subreddit.name)
.equatable()) {
Text(subreddit.name)
}
}
} label: {
NavigationLink(destination: SubredditPostsListView(name: multi.subredditsAsName,
customTitle: multi.displayName)
.equatable()) {
Text(multi.displayName)
}
}
SidebarMultiView(multi: multi)
}
}
}
}

private func toggleSidebar() {
NSApp.keyWindow?.firstResponder?.tryToPerform(#selector(NSSplitViewController.toggleSidebar(_:)), with: nil)
}
}
}

struct Sidebar_Previews: PreviewProvider {
Expand Down

0 comments on commit a95b130

Please sign in to comment.