-
Notifications
You must be signed in to change notification settings - Fork 727
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Alexey Naumov
committed
Dec 8, 2024
1 parent
94193d9
commit f98a6e0
Showing
118 changed files
with
3,166 additions
and
5,804 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
// | ||
// CountriesApp.swift | ||
// CountriesSwiftUI | ||
// | ||
// Created by Alexey on 7/11/24. | ||
// Copyright © 2024 Alexey Naumov. All rights reserved. | ||
// | ||
|
||
import SwiftUI | ||
import EnvironmentOverrides | ||
|
||
@main | ||
struct MainApp: App { | ||
|
||
@UIApplicationDelegateAdaptor(AppDelegate.self) var appDelegate | ||
|
||
var body: some Scene { | ||
WindowGroup { | ||
appDelegate.rootView | ||
} | ||
} | ||
} | ||
|
||
extension AppEnvironment { | ||
var rootView: some View { | ||
VStack { | ||
if isRunningTests { | ||
Text("Running unit tests") | ||
} else { | ||
CountriesList() | ||
.modifier(RootViewAppearance()) | ||
.modelContainer(modelContainer) | ||
.attachEnvironmentOverrides(onChange: onChangeHandler) | ||
.inject(diContainer) | ||
if modelContainer.isStub { | ||
Text("⚠️ There is an issue with local database") | ||
.font(.caption2) | ||
} | ||
} | ||
} | ||
} | ||
|
||
private var onChangeHandler: (EnvironmentValues.Diff) -> Void { | ||
return { diff in | ||
if !diff.isDisjoint(with: [.locale, .sizeCategory]) { | ||
self.diContainer.appState[\.routing] = AppState.ViewRouting() | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
// | ||
// AppDelegate.swift | ||
// CountriesSwiftUI | ||
// | ||
// Created by Alexey Naumov on 23.10.2019. | ||
// Copyright © 2019 Alexey Naumov. All rights reserved. | ||
// | ||
|
||
import UIKit | ||
import SwiftUI | ||
import Combine | ||
import Foundation | ||
|
||
@MainActor | ||
final class AppDelegate: UIResponder, UIApplicationDelegate { | ||
|
||
private lazy var environment = AppEnvironment.bootstrap() | ||
private var systemEventsHandler: SystemEventsHandler { environment.systemEventsHandler } | ||
|
||
var rootView: some View { | ||
environment.rootView | ||
} | ||
|
||
func application(_ application: UIApplication, didFinishLaunchingWithOptions | ||
launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool { | ||
return true | ||
} | ||
|
||
func application(_ application: UIApplication, configurationForConnecting connectingSceneSession: UISceneSession, options: UIScene.ConnectionOptions) -> UISceneConfiguration { | ||
let config: UISceneConfiguration = UISceneConfiguration(name: nil, sessionRole: connectingSceneSession.role) | ||
config.delegateClass = SceneDelegate.self | ||
SceneDelegate.register(systemEventsHandler) | ||
return config | ||
} | ||
|
||
func application(_ application: UIApplication, didRegisterForRemoteNotificationsWithDeviceToken deviceToken: Data) { | ||
systemEventsHandler.handlePushRegistration(result: .success(deviceToken)) | ||
} | ||
|
||
func application(_ application: UIApplication, didFailToRegisterForRemoteNotificationsWithError error: Error) { | ||
systemEventsHandler.handlePushRegistration(result: .failure(error)) | ||
} | ||
|
||
func application(_ application: UIApplication, didReceiveRemoteNotification userInfo: [AnyHashable: Any]) async -> UIBackgroundFetchResult { | ||
return await systemEventsHandler | ||
.appDidReceiveRemoteNotification(payload: userInfo) | ||
} | ||
} | ||
|
||
// MARK: - SceneDelegate | ||
|
||
@MainActor | ||
final class SceneDelegate: UIResponder, UIWindowSceneDelegate, ObservableObject { | ||
|
||
private static var systemEventsHandler: SystemEventsHandler? | ||
private var systemEventsHandler: SystemEventsHandler? { Self.systemEventsHandler } | ||
|
||
static func register(_ systemEventsHandler: SystemEventsHandler?) { | ||
Self.systemEventsHandler = systemEventsHandler | ||
} | ||
|
||
func scene(_ scene: UIScene, openURLContexts URLContexts: Set<UIOpenURLContext>) { | ||
systemEventsHandler?.sceneOpenURLContexts(URLContexts) | ||
} | ||
|
||
func sceneDidBecomeActive(_ scene: UIScene) { | ||
systemEventsHandler?.sceneDidBecomeActive() | ||
} | ||
|
||
func sceneWillResignActive(_ scene: UIScene) { | ||
systemEventsHandler?.sceneWillResignActive() | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.