Skip to content

Commit

Permalink
Fix iPad sidebar (#1338)
Browse files Browse the repository at this point in the history
  • Loading branch information
Sjmarf authored Sep 20, 2024
1 parent 14b4cc0 commit 63abf6b
Show file tree
Hide file tree
Showing 6 changed files with 77 additions and 53 deletions.
4 changes: 4 additions & 0 deletions Mlem.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,7 @@
03531EEE2C2D9298004A3464 /* SearchSheetView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 03531EED2C2D9298004A3464 /* SearchSheetView.swift */; };
03531EF12C2DA298004A3464 /* SearchResultsView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 03531EF02C2DA298004A3464 /* SearchResultsView.swift */; };
03531EF52C2DA610004A3464 /* NavigationSearchType.swift in Sources */ = {isa = PBXBuildFile; fileRef = 03531EF42C2DA610004A3464 /* NavigationSearchType.swift */; };
035394862C9CDC1100795AA5 /* SubscriptionListNavigationButton.swift in Sources */ = {isa = PBXBuildFile; fileRef = 035394852C9CDC1100795AA5 /* SubscriptionListNavigationButton.swift */; };
0355F9462C150B2300605248 /* ExternalApiInfoView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 0355F9452C150B2300605248 /* ExternalApiInfoView.swift */; };
0355F9492C16406E00605248 /* Line.swift in Sources */ = {isa = PBXBuildFile; fileRef = 0355F9482C16406E00605248 /* Line.swift */; };
035BE0872BDD8DA000F77D73 /* NavigationRootView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 035BE0862BDD8DA000F77D73 /* NavigationRootView.swift */; };
Expand Down Expand Up @@ -457,6 +458,7 @@
03531EED2C2D9298004A3464 /* SearchSheetView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SearchSheetView.swift; sourceTree = "<group>"; };
03531EF02C2DA298004A3464 /* SearchResultsView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SearchResultsView.swift; sourceTree = "<group>"; };
03531EF42C2DA610004A3464 /* NavigationSearchType.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = NavigationSearchType.swift; sourceTree = "<group>"; };
035394852C9CDC1100795AA5 /* SubscriptionListNavigationButton.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SubscriptionListNavigationButton.swift; sourceTree = "<group>"; };
0355F9452C150B2300605248 /* ExternalApiInfoView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ExternalApiInfoView.swift; sourceTree = "<group>"; };
0355F9482C16406E00605248 /* Line.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Line.swift; sourceTree = "<group>"; };
035BE0862BDD8DA000F77D73 /* NavigationRootView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = NavigationRootView.swift; sourceTree = "<group>"; };
Expand Down Expand Up @@ -1265,6 +1267,7 @@
CD7DB9742C4D6BEF00DCC542 /* Feed Comments */,
CD4BAD342B4B2C0B00A1E726 /* FeedsView.swift */,
031E2D502BEF961D0003BC45 /* SubscriptionListView.swift */,
035394852C9CDC1100795AA5 /* SubscriptionListNavigationButton.swift */,
03DAEA762C64074E0064DE64 /* SubscriptionListItemView.swift */,
CD9CFA2D2C2E22E200739BBC /* Feed Header */,
CDE021AB2BFA43220052FD61 /* Feed Posts */,
Expand Down Expand Up @@ -2055,6 +2058,7 @@
CD4E386D2C836F8C009B24F2 /* UIUserInterfaceStyle+Extensions.swift in Sources */,
0355F9492C16406E00605248 /* Line.swift in Sources */,
CD4D58A52B86BD1B00B82964 /* PersistenceRepository.swift in Sources */,
035394862C9CDC1100795AA5 /* SubscriptionListNavigationButton.swift in Sources */,
039F58842C7A7F2C00C61658 /* CommentJumpButtonLocation.swift in Sources */,
CD1B2E212C7F84160075C7EA /* View+MarkReadOnScroll.swift in Sources */,
033F84AD2C298466002E3EDF /* SectionIndexTitles.swift in Sources */,
Expand Down
64 changes: 33 additions & 31 deletions Mlem/App/Views/Root/Tabs/Feeds/SubscriptionListItemView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -19,46 +19,48 @@ struct SubscriptionListItemView: View {
let sectionIndicesShown: Bool

var body: some View {
NavigationLink(.community(community)) {
HStack(spacing: 15, content: label)
}
.contextMenu { community.menuActions(feedback: [.toast], navigation: navigation) }
.swipeActions(edge: .trailing) {
Button("Unsubscribe", systemImage: Icons.failure) {
community.toggleSubscribe(feedback: [.toast])
SubscriptionListNavigationButton(.community(community), label: label)
.contextMenu { community.menuActions(feedback: [.toast], navigation: navigation) }
.swipeActions(edge: .trailing) {
Button("Unsubscribe", systemImage: Icons.failure) {
community.toggleSubscribe(feedback: [.toast])
}
.labelStyle(.iconOnly)
.tint(.red)
}
.labelStyle(.iconOnly)
.tint(.red)
}
.padding(.trailing, sectionIndicesShown ? 5 : 0)
.padding(.trailing, sectionIndicesShown ? 5 : 0)
}

@ViewBuilder
private func label() -> some View {
switch instanceLocation(section: section) {
case .trailing:
CircleCroppedImageView(community, frame: 28)
(
Text(community.name)
+ Text(verbatim: "@\(community.host ?? "unknown")")
.foregroundStyle(.secondary)
.font(.footnote)
)
.lineLimit(1)
case .bottom:
CircleCroppedImageView(community, frame: 36)
VStack(alignment: .leading, spacing: 0) {
HStack(spacing: 15) {
switch instanceLocation(section: section) {
case .trailing:
CircleCroppedImageView(community, frame: 28)
(
Text(community.name)
+ Text(verbatim: "@\(community.host ?? "unknown")")
.foregroundStyle(.secondary)
.font(.footnote)
)
.lineLimit(1)
case .bottom:
CircleCroppedImageView(community, frame: 36)
VStack(alignment: .leading, spacing: 0) {
Text(community.name)
.lineLimit(1)
Text(verbatim: "@\(community.host ?? "")")
.foregroundStyle(.secondary)
.font(.footnote)
}
case .disabled:
CircleCroppedImageView(community, frame: 28)
Text(community.name)
.lineLimit(1)
Text(verbatim: "@\(community.host ?? "")")
.foregroundStyle(.secondary)
.font(.footnote)
}
case .disabled:
CircleCroppedImageView(community, frame: 28)
Text(community.name)
.lineLimit(1)
}
.frame(maxWidth: .infinity, alignment: .leading)
.contentShape(.rect)
}

private func instanceLocation(section: SubscriptionListSection) -> InstanceLocation {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
//
// SubscriptionListNavigationButton.swift
// Mlem
//
// Created by Sjmarf on 19/09/2024.
//

import SwiftUI

struct SubscriptionListNavigationButton<Content: View>: View {
@Environment(NavigationLayer.self) var navigation
let destination: NavigationPage
@ViewBuilder var label: () -> Content

init(_ destination: NavigationPage, @ViewBuilder label: @escaping () -> Content) {
self.destination = destination
self.label = label
}

var body: some View {
MultiplatformView(phone: {
NavigationLink(destination, label: label)
}, pad: {
Button(action: {
navigation.root = destination
}, label: label)
.buttonStyle(EmptyButtonStyle())
})
}
}
5 changes: 3 additions & 2 deletions Mlem/App/Views/Root/Tabs/Feeds/SubscriptionListView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -45,12 +45,13 @@ struct SubscriptionListView: View {
Form {
Section {
ForEach(feedOptions, id: \.hashValue) { feedOption in
NavigationLink(.feeds(feedOption)) {
SubscriptionListNavigationButton(.feeds(feedOption)) {
HStack(spacing: 15) {
FeedIconView(feedDescription: feedOption.description, size: 28)

Text(feedOption.description.label)
}
.frame(maxWidth: .infinity, alignment: .leading)
.contentShape(.rect)
}
}
}
Expand Down
26 changes: 6 additions & 20 deletions Mlem/App/Views/Shared/Navigation/NavigationLayerView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -7,18 +7,6 @@

import SwiftUI

struct DeferredContextMenu<Content: View>: View {
let content: () -> Content

init(@ViewBuilder content: @escaping () -> Content) {
self.content = content
}

var body: some View {
content()
}
}

struct NavigationLayerView: View {
@Bindable var layer: NavigationLayer
let hasSheetModifiers: Bool
Expand All @@ -27,14 +15,12 @@ struct NavigationLayerView: View {
Group {
if layer.hasNavigationStack {
NavigationStack(path: $layer.path) {
DeferredContextMenu {
rootView()
.environment(\.isRootView, true)
}
.navigationDestination(for: NavigationPage.self) {
$0.view()
.environment(\.isRootView, false)
}
rootView()
.environment(\.isRootView, true)
.navigationDestination(for: NavigationPage.self) {
$0.view()
.environment(\.isRootView, false)
}
}

} else {
Expand Down
1 change: 1 addition & 0 deletions Mlem/App/Views/Shared/Navigation/NavigationRootView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ struct NavigationSplitRootView: View {
},
detail: {
NavigationLayerView(layer: layer, hasSheetModifiers: false)
.id(layer.root)
}
)
}
Expand Down

0 comments on commit 63abf6b

Please sign in to comment.