Skip to content

Commit ccd2c05

Browse files
committed
RouteComposer refactor, bug fixes
1 parent 528a036 commit ccd2c05

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

43 files changed

+629
-638
lines changed

ForPDA.xcodeproj/project.pbxproj

Lines changed: 65 additions & 76 deletions
Large diffs are not rendered by default.

ForPDA.xcodeproj/project.xcworkspace/xcshareddata/swiftpm/Package.resolved

Lines changed: 9 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

ForPDA/Info.plist

Lines changed: 17 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,21 +2,32 @@
22
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
33
<plist version="1.0">
44
<dict>
5+
<key>CFBundleURLTypes</key>
6+
<array>
7+
<dict>
8+
<key>CFBundleTypeRole</key>
9+
<string>Editor</string>
10+
<key>CFBundleURLSchemes</key>
11+
<array>
12+
<string>com.forpda</string>
13+
</array>
14+
</dict>
15+
</array>
16+
<key>ITSAppUsesNonExemptEncryption</key>
17+
<false/>
518
<key>SECRET_KEYS</key>
619
<dict>
20+
<key>AMPLITUDE_TOKEN</key>
21+
<string>$(AMPLITUDE_TOKEN)</string>
722
<key>SENTRY_DSN</key>
823
<string>$(SENTRY_DSN)</string>
924
<key>SENTRY_DSYM_TOKEN</key>
1025
<string>$(SENTRY_DSYM_TOKEN)</string>
11-
<key>AMPLITUDE_TOKEN</key>
12-
<string>$(AMPLITUDE_TOKEN)</string>
13-
<key>TELEGRAM_TOKEN</key>
14-
<string>$(TELEGRAM_TOKEN)</string>
1526
<key>TELEGRAM_CHAT_ID</key>
1627
<string>$(TELEGRAM_CHAT_ID)</string>
28+
<key>TELEGRAM_TOKEN</key>
29+
<string>$(TELEGRAM_TOKEN)</string>
1730
</dict>
18-
<key>ITSAppUsesNonExemptEncryption</key>
19-
<false/>
2031
<key>UIApplicationSceneManifest</key>
2132
<dict>
2233
<key>UIApplicationSupportsMultipleScenes</key>

ForPDA/Sources/Application/AppDelegate.swift

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import SnapKit
1010
import Factory
1111
import Sentry
1212
import Nuke
13+
import RouteComposer
1314

1415
@main
1516
class AppDelegate: UIResponder, UIApplicationDelegate {
@@ -22,6 +23,7 @@ class AppDelegate: UIResponder, UIApplicationDelegate {
2223
SentrySDK.start { options in
2324
options.dsn = Secrets.for(key: .SENTRY_DSN)
2425
options.debug = AppScheme.isDebug
26+
options.enabled = !AppScheme.isDebug
2527
options.tracesSampleRate = 1.0
2628
options.diagnosticLevel = .warning
2729
options.attachScreenshot = true

ForPDA/Sources/Application/SceneDelegate.swift

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,14 +7,12 @@
77

88
import UIKit
99
import Factory
10-
import XCoordinator
10+
import RouteComposer
1111
import WebKit
1212

1313
class SceneDelegate: UIResponder, UIWindowSceneDelegate {
1414

1515
@Injected(\.settingsService) private var settingsService
16-
17-
private let coordinator = HomeCoordinator().strongRouter
1816

1917
var window: UIWindow?
2018

@@ -24,9 +22,13 @@ class SceneDelegate: UIResponder, UIWindowSceneDelegate {
2422
guard let windowScene = (scene as? UIWindowScene) else { return }
2523
self.window = UIWindow(windowScene: windowScene)
2624

25+
window?.rootViewController = UIViewController()
26+
window?.makeKeyAndVisible()
27+
2728
overrideApplicationThemeStyle(with: settingsService.getAppTheme())
2829
configureWKWebView()
29-
coordinator.setRoot(for: window!)
30+
31+
try? DefaultRouter().navigate(to: RouteMap.tabBarScreen, with: nil)
3032
}
3133

3234
private func configureWKWebView() {
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
//
2+
// Errors.swift
3+
// ForPDA
4+
//
5+
// Created by Subvert on 19.08.2023.
6+
//
7+
// swiftlint:disable unneeded_synthesized_initializer
8+
9+
import Foundation
10+
11+
struct FailingRouterIgnoreError: Error {
12+
13+
let underlyingError: Error
14+
15+
init(underlyingError: Error) {
16+
self.underlyingError = underlyingError
17+
}
18+
19+
}
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
//
2+
// LoginInterceptor.swift
3+
// ForPDA
4+
//
5+
// Created by Subvert on 19.08.2023.
6+
//
7+
8+
import UIKit
9+
import RouteComposer
10+
11+
final class LoginInterceptor<C>: RoutingInterceptor {
12+
13+
typealias Context = C
14+
15+
func perform(with context: Context, completion: @escaping (_: RoutingResult) -> Void) {
16+
guard SettingsService().getUser() == nil else {
17+
completion(.success)
18+
return
19+
}
20+
21+
let router = DefaultRouter()
22+
do {
23+
try router.navigate(to: LoginConfiguration.loginScreen, with: nil, animated: true) { routingResult in
24+
guard routingResult.isSuccessful,
25+
let viewController = ClassFinder<LoginVC, Any?>().getViewController() else {
26+
completion(.failure(RoutingError.compositionFailed(.init("LoginViewController was not found."))))
27+
return
28+
}
29+
viewController.interceptorCompletionBlock = completion
30+
}
31+
} catch {
32+
completion(.failure(RoutingError.compositionFailed(.init(
33+
"Could not present login view controller", underlyingError: error))))
34+
}
35+
}
36+
}
Lines changed: 143 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,143 @@
1+
//
2+
// RouteMap.swift
3+
// ForPDA
4+
//
5+
// Created by Subvert on 13.08.2023.
6+
//
7+
// swiftlint:disable all
8+
9+
import UIKit
10+
import RouteComposer
11+
12+
protocol RouteMapProtocol {
13+
14+
}
15+
16+
struct RouteMap: RouteMapProtocol {
17+
18+
// MARK: - [TabBar]
19+
20+
static var tabBarScreen: DestinationStep<PDATabBarController, Any?> {
21+
StepAssembly(
22+
finder: ClassFinder(), // В чем разница с <PDATabBarController, Any?>(options: .current, startingPoint: .root)?
23+
factory: CompleteFactoryAssembly(factory: PDATabBarControllerFactory<PDATabBarController, Any?>())
24+
.with(createNewsWithNavigationFactory(), using: PDATabBarController.add())
25+
.with(createForumWithNavigationFactory(), using: PDATabBarController.add())
26+
.with(createMenuWithNavigationFactory(), using: PDATabBarController.add())
27+
.assemble())
28+
.using(GeneralAction.replaceRoot())
29+
.from(GeneralStep.root())
30+
.assemble()
31+
}
32+
33+
// MARK: - [News]
34+
35+
static var newsScreen: DestinationStep<NewsVC, Any?> {
36+
StepAssembly(
37+
finder: ClassFinder<NewsVC, Any?>(),
38+
factory: NilFactory())
39+
.from(tabBarScreen)
40+
.assemble()
41+
}
42+
43+
// MARK: Article
44+
45+
static var articleScreen: DestinationStep<ArticleVC, Article> {
46+
StepAssembly(
47+
finder: ClassFinder<ArticleVC, Article>(),
48+
factory: ArticleFactory())
49+
.using(UINavigationController.push())
50+
.from(newsScreen.expectingContainer())
51+
.assemble()
52+
}
53+
54+
// MARK: - [Forum]
55+
56+
static var forumScreen: DestinationStep<ForumVC, Any?> {
57+
StepAssembly(finder: ClassFinder<ForumVC, Any?>(),
58+
factory: NilFactory())
59+
.from(tabBarScreen)
60+
.assemble()
61+
}
62+
63+
// MARK: - [Menu]
64+
65+
static var menuScreen: DestinationStep<MenuVC, Any?> {
66+
StepAssembly(
67+
finder: ClassFinder<MenuVC, Any?>(),
68+
factory: NilFactory())
69+
.from(tabBarScreen)
70+
.assemble()
71+
}
72+
73+
// MARK: Profile
74+
75+
static var profileScreen: DestinationStep<ProfileVC, Any?> {
76+
StepAssembly(
77+
finder: ClassFinder(),
78+
factory: ProfileFactory())
79+
.adding(LoginInterceptor())
80+
.using(UINavigationController.push())
81+
.from(menuScreen.expectingContainer())
82+
// .from(GeneralStep.custom(using: ClassFinder<UINavigationController, Any?>()))
83+
.assemble()
84+
}
85+
86+
// MARK: Settings
87+
88+
static var settingsScreen: DestinationStep<SettingsVC, Any?> {
89+
StepAssembly(
90+
finder: ClassFinder(),
91+
factory: SettingsFactory())
92+
.using(UINavigationController.push())
93+
.from(menuScreen.expectingContainer())
94+
.assemble()
95+
}
96+
}
97+
98+
// MARK: - LoginConfiguration
99+
100+
struct LoginConfiguration {
101+
102+
static var loginScreen: DestinationStep<LoginVC, Any?> {
103+
StepAssembly(
104+
finder: ClassFinder(),
105+
factory: LoginFactory())
106+
.using(UINavigationController.push())
107+
.from(GeneralStep.custom(using: ClassFinder<UINavigationController, Any?>()))
108+
.assemble()
109+
}
110+
111+
// static func createLoginWithNavigationFactory() -> CompleteFactory<NavigationControllerFactory<UINavigationController, Any?>> {
112+
// return CompleteFactoryAssembly(
113+
// factory: NavigationControllerFactory())
114+
// .with(LoginFactory(), using: UINavigationController.pushAsRoot())
115+
// .assemble()
116+
// }
117+
}
118+
119+
// MARK: - NavCon Factories
120+
121+
extension RouteMap {
122+
123+
static func createNewsWithNavigationFactory() -> CompleteFactory<NavigationControllerFactory<UINavigationController, Any?>> {
124+
return CompleteFactoryAssembly(
125+
factory: NavigationControllerFactory())
126+
.with(NewsFactory(), using: UINavigationController.pushAsRoot())
127+
.assemble()
128+
}
129+
130+
static func createForumWithNavigationFactory() -> CompleteFactory<NavigationControllerFactory<UINavigationController, Any?>> {
131+
return CompleteFactoryAssembly(
132+
factory: NavigationControllerFactory())
133+
.with(ForumFactory(), using: UINavigationController.pushAsRoot())
134+
.assemble()
135+
}
136+
137+
static func createMenuWithNavigationFactory() -> CompleteFactory<NavigationControllerFactory<UINavigationController, Any?>> {
138+
return CompleteFactoryAssembly(
139+
factory: NavigationControllerFactory())
140+
.with(MenuFactory(), using: UINavigationController.pushAsRoot())
141+
.assemble()
142+
}
143+
}

ForPDA/Sources/Coordinators/ForumCoordinator.swift

Lines changed: 0 additions & 28 deletions
This file was deleted.

0 commit comments

Comments
 (0)