Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Navigation: SPM local package #657

Closed
wants to merge 8 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
81 changes: 37 additions & 44 deletions Mlem.xcodeproj/project.pbxproj

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions Mlem/Extensions/Navigation getter.swift
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,11 @@ extension EnvironmentValues {
// MARK: - Mlem NavigationRoute

private struct NavigationPathWithRoutes: EnvironmentKey {
static let defaultValue: Binding<[NavigationRoute]> = .constant([])
static let defaultValue: Binding<[AppRoute]> = .constant([])
}

extension EnvironmentValues {
var navigationPathWithRoutes: Binding<[NavigationRoute]> {
var navigationPathWithRoutes: Binding<[AppRoute]> {
get { self[NavigationPathWithRoutes.self] }
set { self[NavigationPathWithRoutes.self] = newValue }
}
Expand Down
105 changes: 102 additions & 3 deletions Mlem/Extensions/View - Handle Lemmy Links.swift
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,12 @@

import Dependencies
import Foundation
import Navigation
import SwiftUI

struct HandleLemmyLinksDisplay: ViewModifier {
@Environment(\.navigationPath) private var navigationPath
@EnvironmentObject private var layoutWidgetTracker: LayoutWidgetTracker
@EnvironmentObject var appState: AppState
@EnvironmentObject var filtersTracker: FiltersTracker

Expand All @@ -18,9 +21,10 @@ struct HandleLemmyLinksDisplay: ViewModifier {
@AppStorage("upvoteOnSave") var upvoteOnSave = false

// swiftlint:disable function_body_length
// swiftlint:disable:next cyclomatic_complexity
func body(content: Content) -> some View {
content
.navigationDestination(for: NavigationRoute.self) { route in
.navigationDestination(for: AppRoute.self) { route in
switch route {
case .apiCommunity(let community):
FeedView(community: community, feedType: .all, sortType: defaultPostSorting)
Expand Down Expand Up @@ -70,13 +74,108 @@ struct HandleLemmyLinksDisplay: ViewModifier {
case .userModeratorLink(let user):
UserModeratorView(userDetails: user.user, moderatedCommunities: user.moderatedCommunities)
.environmentObject(appState)
case .settings(let page):
settingsDestination(for: page)
case .aboutSettings(let page):
aboutSettingsDestination(for: page)
case .appearanceSettings(let page):
appearanceSettingsDestination(for: page)
case .commentSettings(let page):
commentSettingsDestination(for: page)
case .postSettings(let page):
postSettingsDestination(for: page)
case .licenseSettings(let page):
licensesSettingsDestination(for: page)
}
}
}
// swiftlint:enable function_body_length

@ViewBuilder
private func settingsDestination(for page: SettingsPage) -> some View {
switch page {
case .accounts:
AccountsPage()
case .general:
GeneralSettingsView()
case .accessibility:
AccessibilitySettingsView()
case .appearance:
AppearanceSettingsView()
case .contentFilters:
FiltersSettingsView()
case .about:
AboutView(navigationPath: navigationPath)
case .advanced:
AdvancedSettingsView()
}
}

@ViewBuilder
private func aboutSettingsDestination(for page: AboutSettingsPage) -> some View {
switch page {
case .contributors:
ContributorsView()
case let .document(doc):
DocumentView(text: doc.body)
case .licenses:
LicensesView()
}
}

@ViewBuilder
private func appearanceSettingsDestination(for page: AppearanceSettingsPage) -> some View {
switch page {
case .theme:
ThemeSettingsView()
case .appIcon:
IconSettingsView()
case .posts:
PostSettingsView()
case .comments:
CommentSettingsView()
case .communities:
CommunitySettingsView()
case .users:
UserSettingsView()
case .tabBar:
TabBarSettingsView()
}
}

@ViewBuilder
private func commentSettingsDestination(for page: CommentSettingsPage) -> some View {
switch page {
case .layoutWidget:
LayoutWidgetEditView(widgets: layoutWidgetTracker.groups.comment, onSave: { widgets in
layoutWidgetTracker.groups.comment = widgets
layoutWidgetTracker.saveLayoutWidgets()
})
}
}

@ViewBuilder
private func postSettingsDestination(for page: PostSettingsPage) -> some View {
switch page {
case .customizeWidgets:
/// We really should be passing in the layout widget through the route enum value, but that would involve making layout widget tracker hashable and codable.
LayoutWidgetEditView(widgets: layoutWidgetTracker.groups.post, onSave: { widgets in
layoutWidgetTracker.groups.post = widgets
layoutWidgetTracker.saveLayoutWidgets()
})
}
}

@ViewBuilder
private func licensesSettingsDestination(for page: LicensesSettingsPage) -> some View {
switch page {
case let .licenseDocument(doc):
DocumentView(text: doc.body)
}
}
}

struct HandleLemmyLinkResolution<Path: AnyNavigationPath>: ViewModifier {
struct HandleLemmyLinkResolution<Path: AnyNavigablePath>: ViewModifier {
@Dependency(\.apiClient) var apiClient
@Dependency(\.errorHandler) var errorHandler
@Dependency(\.notifier) var notifier
Expand Down Expand Up @@ -180,7 +279,7 @@ extension View {
modifier(HandleLemmyLinksDisplay())
}

func handleLemmyLinkResolution<P: AnyNavigationPath>(navigationPath: Binding<P>) -> some View {
func handleLemmyLinkResolution<P: AnyNavigablePath>(navigationPath: Binding<P>) -> some View {
modifier(HandleLemmyLinkResolution(navigationPath: navigationPath))
}
}
48 changes: 48 additions & 0 deletions Mlem/Navigation/Destination Values/SettingsValues.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
//
// SettingsRoutes.swift
// Mlem
//
// Created by Bosco Ho on 2023-08-18.
//

import Foundation
import Navigation

enum SettingsPage: DestinationValue {
case accounts
case general
case accessibility
case appearance
case contentFilters
case about
case advanced
}

enum AboutSettingsPage: DestinationValue {
case contributors
/// e.g. `Privacy Policy` or `EULA`.
case document(Document)
case licenses
}

enum AppearanceSettingsPage: DestinationValue {
case theme
case appIcon
case posts
case comments
case communities
case users
case tabBar
}

enum CommentSettingsPage: DestinationValue {
case layoutWidget
}

enum PostSettingsPage: DestinationValue {
case customizeWidgets
}

enum LicensesSettingsPage: DestinationValue {
case licenseDocument(Document)
}
2 changes: 1 addition & 1 deletion Mlem/Navigation/NavigationLink+Helpers.swift
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import SwiftUI
extension NavigationLink where Destination == Never {

/// Convenience initializer.
init(_ route: NavigationRoute, @ViewBuilder label: () -> Label) {
init(_ route: AppRoute, @ViewBuilder label: () -> Label) {
self = .init(value: route, label: label)
}
}
95 changes: 0 additions & 95 deletions Mlem/Navigation/Route/SettingsRoutes.swift

This file was deleted.

46 changes: 0 additions & 46 deletions Mlem/Navigation/Router/NavigationRouter.swift

This file was deleted.

Loading