From 78ca37c4af97d105810e31a7b0e8e715d792c033 Mon Sep 17 00:00:00 2001 From: Bosco Ho Date: Tue, 26 Sep 2023 22:56:53 -0700 Subject: [PATCH] - Move `OnboardingRoutes` to navigation directory to separate views from the data that drives the presentation of views. - Add documentation. --- Mlem.xcodeproj/project.pbxproj | 8 ++++---- Mlem/Navigation/AnyNavigationPath.swift | 4 ++++ Mlem/Navigation/Routes/AppRoutes.swift | 3 +++ .../Routes/OnboardingRoutes.swift} | 3 ++- 4 files changed, 13 insertions(+), 5 deletions(-) rename Mlem/{Views/Onboarding/OnboardingRoute.swift => Navigation/Routes/OnboardingRoutes.swift} (65%) diff --git a/Mlem.xcodeproj/project.pbxproj b/Mlem.xcodeproj/project.pbxproj index 449cf11f2..022326966 100644 --- a/Mlem.xcodeproj/project.pbxproj +++ b/Mlem.xcodeproj/project.pbxproj @@ -43,7 +43,7 @@ 503BA26F2A2C94540052516C /* URL+Identifiable.swift in Sources */ = {isa = PBXBuildFile; fileRef = 503BA26E2A2C94540052516C /* URL+Identifiable.swift */; }; 504106CD2A744D7F000AAEF8 /* CommentRepository+Dependency.swift in Sources */ = {isa = PBXBuildFile; fileRef = 504106CC2A744D7F000AAEF8 /* CommentRepository+Dependency.swift */; }; 504ECBAA2AB27C73006C0B96 /* LandingPage.swift in Sources */ = {isa = PBXBuildFile; fileRef = 504ECBA92AB27C73006C0B96 /* LandingPage.swift */; }; - 504ECBAC2AB27CB1006C0B96 /* OnboardingRoute.swift in Sources */ = {isa = PBXBuildFile; fileRef = 504ECBAB2AB27CB1006C0B96 /* OnboardingRoute.swift */; }; + 504ECBAC2AB27CB1006C0B96 /* OnboardingRoutes.swift in Sources */ = {isa = PBXBuildFile; fileRef = 504ECBAB2AB27CB1006C0B96 /* OnboardingRoutes.swift */; }; 504ECBAE2AB45B2A006C0B96 /* LemmyURL.swift in Sources */ = {isa = PBXBuildFile; fileRef = 504ECBAD2AB45B2A006C0B96 /* LemmyURL.swift */; }; 504ECBB12AB4B101006C0B96 /* LemmyURLTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 504ECBB02AB4B101006C0B96 /* LemmyURLTests.swift */; }; 505240E32A86916500EA4558 /* FavoriteCommunitiesTracker+Dependency.swift in Sources */ = {isa = PBXBuildFile; fileRef = 505240E22A86916500EA4558 /* FavoriteCommunitiesTracker+Dependency.swift */; }; @@ -494,7 +494,7 @@ 503BA26E2A2C94540052516C /* URL+Identifiable.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "URL+Identifiable.swift"; sourceTree = ""; }; 504106CC2A744D7F000AAEF8 /* CommentRepository+Dependency.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = "CommentRepository+Dependency.swift"; sourceTree = ""; }; 504ECBA92AB27C73006C0B96 /* LandingPage.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = LandingPage.swift; sourceTree = ""; }; - 504ECBAB2AB27CB1006C0B96 /* OnboardingRoute.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = OnboardingRoute.swift; sourceTree = ""; }; + 504ECBAB2AB27CB1006C0B96 /* OnboardingRoutes.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = OnboardingRoutes.swift; sourceTree = ""; }; 504ECBAD2AB45B2A006C0B96 /* LemmyURL.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = LemmyURL.swift; sourceTree = ""; }; 504ECBB02AB4B101006C0B96 /* LemmyURLTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = LemmyURLTests.swift; sourceTree = ""; }; 505240E22A86916500EA4558 /* FavoriteCommunitiesTracker+Dependency.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "FavoriteCommunitiesTracker+Dependency.swift"; sourceTree = ""; }; @@ -1087,7 +1087,6 @@ children = ( 504ECBA92AB27C73006C0B96 /* LandingPage.swift */, CDE3BA862A8C25B000B972E2 /* OnboardingView.swift */, - 504ECBAB2AB27CB1006C0B96 /* OnboardingRoute.swift */, ); path = Onboarding; sourceTree = ""; @@ -2265,6 +2264,7 @@ children = ( E49E01F32ABD99D300E42BB3 /* Routable.swift */, E40E018B2AABF85500410B2C /* AppRoutes.swift */, + 504ECBAB2AB27CB1006C0B96 /* OnboardingRoutes.swift */, ); path = Routes; sourceTree = ""; @@ -2759,7 +2759,7 @@ 637218432A3A2AAD008C4816 /* APIClient.swift in Sources */, CD82A2572A716D7C00111034 /* PersonRepository+Dependency.swift in Sources */, 63DF71F12A02999C002AC14E /* App Constants.swift in Sources */, - 504ECBAC2AB27CB1006C0B96 /* OnboardingRoute.swift in Sources */, + 504ECBAC2AB27CB1006C0B96 /* OnboardingRoutes.swift in Sources */, CD82A2532A716B8100111034 /* PersonRepository.swift in Sources */, CD69F55F2A40121D0028D4F7 /* Ellipsis Menu.swift in Sources */, 638535712A1779BC00815781 /* GeneralSettingsView.swift in Sources */, diff --git a/Mlem/Navigation/AnyNavigationPath.swift b/Mlem/Navigation/AnyNavigationPath.swift index 39ce998d1..e2c72e5f1 100644 --- a/Mlem/Navigation/AnyNavigationPath.swift +++ b/Mlem/Navigation/AnyNavigationPath.swift @@ -7,6 +7,10 @@ import Foundation +/// For when the system `NavigationPath` doesn't meet your needs. +/// +/// Technical Note: +/// - [2023.09] Initially, enum-based navigation routes were added during the development of tab-bar navigation. When using the system `NavigationPath`, the UI would exhibit a bug where views would randomly push onto view without any animations, after which the navigation path became corrupt, making programmatic navigation unreliable. Using enum-based navigation routes with custom navigation paths resulted in this issue disappearing on both iOS 16/17. final class AnyNavigationPath: ObservableObject { /// - Avoid directly manipulating this value, if alternate methods are provided. diff --git a/Mlem/Navigation/Routes/AppRoutes.swift b/Mlem/Navigation/Routes/AppRoutes.swift index 4cc9bebab..1ac472e8b 100644 --- a/Mlem/Navigation/Routes/AppRoutes.swift +++ b/Mlem/Navigation/Routes/AppRoutes.swift @@ -8,6 +8,8 @@ import Foundation /// Possible routes for navigation links in `Mlem.app`. +/// +/// For simple (i.e. linear) navigation flows, you may wish to define a separate set of routes. For example, see `OnboardingRoutes`. enum AppRoute: Routable { case apiCommunityView(APICommunityView) case apiCommunity(APICommunity) @@ -24,6 +26,7 @@ enum AppRoute: Routable { case lazyLoadPostLinkWithContext(LazyLoadPostLinkWithContext) case userModeratorLink(UserModeratorLink) + // MARK: - Settings case settings(SettingsPage) case aboutSettings(AboutSettingsPage) case appearanceSettings(AppearanceSettingsPage) diff --git a/Mlem/Views/Onboarding/OnboardingRoute.swift b/Mlem/Navigation/Routes/OnboardingRoutes.swift similarity index 65% rename from Mlem/Views/Onboarding/OnboardingRoute.swift rename to Mlem/Navigation/Routes/OnboardingRoutes.swift index 24fd3f39d..e719139c6 100644 --- a/Mlem/Views/Onboarding/OnboardingRoute.swift +++ b/Mlem/Navigation/Routes/OnboardingRoutes.swift @@ -8,7 +8,8 @@ import Foundation -enum OnboardingRoute: Hashable { +/// Routes for Onboarding navigation flow. +enum OnboardingRoute: Routable { case onboard case login(URL?) }