From 53faeb619d9d58d9addd24f066d7133ae98295e1 Mon Sep 17 00:00:00 2001 From: Alexandr Romanov Date: Sat, 9 Nov 2024 20:32:24 +0300 Subject: [PATCH] Up to Swift6 --- Package.swift | 9 +- .../OversizeRouter/Protocols/Alertable.swift | 2 +- .../OversizeRouter/Protocols/Routable.swift | 4 +- .../OversizeRouter/Protocols/Tabable.swift | 10 +-- .../Router/Alert/AlertResolve.swift | 16 +++- Sources/OversizeRouter/Router/HUDRouter.swift | 27 +++++- Sources/OversizeRouter/Router/Router.swift | 2 - .../RoutingViews/RoutingSidebarView.swift | 2 - .../RoutingViews/RoutingSplitView.swift | 31 +++++-- .../RoutingViews/RoutingTabView.swift | 1 - .../RoutingViews/RoutingView.swift | 28 ++----- Sources/OversizeRouter/SystemServices.swift | 83 ------------------- 12 files changed, 81 insertions(+), 134 deletions(-) delete mode 100644 Sources/OversizeRouter/SystemServices.swift diff --git a/Package.swift b/Package.swift index 5992f04..d43a401 100644 --- a/Package.swift +++ b/Package.swift @@ -1,4 +1,4 @@ -// swift-tools-version: 5.9 +// swift-tools-version: 6.0 // The swift-tools-version declares the minimum version of Swift required to build this package. import Foundation @@ -6,18 +6,14 @@ import PackageDescription let remoteDependencies: [PackageDescription.Package.Dependency] = [ .package(url: "https://github.com/oversizedev/OversizeUI.git", .upToNextMajor(from: "3.0.2")), - .package(url: "https://github.com/oversizedev/OversizeServices.git", .upToNextMajor(from: "1.4.0")), .package(url: "https://github.com/oversizedev/OversizeModels.git", .upToNextMajor(from: "0.1.0")), - .package(url: "https://github.com/hmlongco/Factory.git", .upToNextMajor(from: "2.1.3")), .package(url: "https://github.com/oversizedev/OversizeLocalizable.git", .upToNextMajor(from: "1.5.0")), ] let localDependencies: [PackageDescription.Package.Dependency] = [ .package(name: "OversizeUI", path: "../OversizeUI"), - .package(name: "OversizeServices", path: "../OversizeServices"), .package(name: "OversizeModels", path: "../OversizeModels"), .package(name: "OversizeLocalizable", path: "../OversizeLocalizable"), - .package(url: "https://github.com/hmlongco/Factory.git", .upToNextMajor(from: "2.1.3")), ] var dependencies: [PackageDescription.Package.Dependency] = localDependencies @@ -45,10 +41,7 @@ let package = Package( .target( name: "OversizeRouter", dependencies: [ - .product(name: "OversizeServices", package: "OversizeServices"), - .product(name: "OversizeStoreService", package: "OversizeServices"), .product(name: "OversizeUI", package: "OversizeUI"), - .product(name: "Factory", package: "Factory"), .product(name: "OversizeModels", package: "OversizeModels"), .product(name: "OversizeLocalizable", package: "OversizeLocalizable"), ] diff --git a/Sources/OversizeRouter/Protocols/Alertable.swift b/Sources/OversizeRouter/Protocols/Alertable.swift index 77ea23c..5cb237f 100644 --- a/Sources/OversizeRouter/Protocols/Alertable.swift +++ b/Sources/OversizeRouter/Protocols/Alertable.swift @@ -5,7 +5,7 @@ import Foundation -public protocol Alertable: Equatable, Hashable, Identifiable {} +public protocol Alertable: Equatable, Hashable, Identifiable, Sendable {} public extension Alertable { static func == (lhs: Self, rhs: Self) -> Bool { diff --git a/Sources/OversizeRouter/Protocols/Routable.swift b/Sources/OversizeRouter/Protocols/Routable.swift index 77560f7..949ffec 100644 --- a/Sources/OversizeRouter/Protocols/Routable.swift +++ b/Sources/OversizeRouter/Protocols/Routable.swift @@ -5,13 +5,13 @@ import SwiftUI +public protocol Routable: Equatable, Hashable, Identifiable, Sendable {} + public protocol RoutableView: Routable { associatedtype ViewType: View func view() -> ViewType } -public protocol Routable: Equatable, Hashable, Identifiable {} - public extension Routable { func hash(into hasher: inout Hasher) { hasher.combine(id) diff --git a/Sources/OversizeRouter/Protocols/Tabable.swift b/Sources/OversizeRouter/Protocols/Tabable.swift index 709b5cb..739c62e 100644 --- a/Sources/OversizeRouter/Protocols/Tabable.swift +++ b/Sources/OversizeRouter/Protocols/Tabable.swift @@ -5,16 +5,16 @@ import SwiftUI +public protocol Tabable: CaseIterable, Equatable, Identifiable, Hashable, Sendable { + var icon: Image { get } + var title: String { get } +} + public protocol TabableView: Tabable { associatedtype ViewType: View func view() -> ViewType } -public protocol Tabable: CaseIterable, Equatable, Identifiable, Hashable { - var icon: Image { get } - var title: String { get } -} - public extension Tabable { func hash(into hasher: inout Hasher) { hasher.combine(id) diff --git a/Sources/OversizeRouter/Router/Alert/AlertResolve.swift b/Sources/OversizeRouter/Router/Alert/AlertResolve.swift index 50579f7..78c4479 100644 --- a/Sources/OversizeRouter/Router/Alert/AlertResolve.swift +++ b/Sources/OversizeRouter/Router/Alert/AlertResolve.swift @@ -8,8 +8,9 @@ import OversizeModels import SwiftUI public enum AppAlert: Alertable { - case dismiss(_ action: () -> Void) - case delete(_ action: () -> Void) + case dismiss(_ action: @Sendable () -> Void) + case delete(_ action: @Sendable () -> Void) + case unsavedChanges(_ action: @Sendable () -> Void) case appError(error: AppError) case text(_ title: String) } @@ -21,6 +22,8 @@ public extension AppAlert { "dismiss" case .delete: "delete" + case .unsavedChanges: + "unsavedChanges" case .appError: "appError" case .text: @@ -44,10 +47,17 @@ public extension AppAlert { primaryButton: .destructive(Text("\(L10n.Button.delete)"), action: action), secondaryButton: .cancel() ) + case let .unsavedChanges(action): + Alert( + title: Text("You have unsaved changes"), + message: Text("Do you want to discard them and switch versions?"), + primaryButton: .destructive(Text("Discard Changes"), action: action), + secondaryButton: .cancel() + ) case let .appError(error: error): Alert( title: Text(error.title), - message: Text(error.subtitle.valueOrEmpty), + message: error.subtitle == nil ? nil : Text(error.subtitle ?? ""), dismissButton: .cancel() ) case let .text(title): diff --git a/Sources/OversizeRouter/Router/HUDRouter.swift b/Sources/OversizeRouter/Router/HUDRouter.swift index cf10460..273bd17 100644 --- a/Sources/OversizeRouter/Router/HUDRouter.swift +++ b/Sources/OversizeRouter/Router/HUDRouter.swift @@ -5,7 +5,7 @@ import Foundation -public enum HUDMessageType { +public enum HUDMessageType: Sendable { case `default` case success case destructive @@ -16,11 +16,19 @@ public enum HUDMessageType { case unfavorite } +public enum HUDLoaderStatus: Sendable { + case progress(Double? = nil) + case success + case failure +} + @Observable public class HUDRouter { public var isShowHud: Bool = false + public var isAutoHide: Bool = true public var hudText: String = "" public var style: HUDMessageType = .default + public var loaderStatus: HUDLoaderStatus = .progress(nil) public init() {} } @@ -29,6 +37,23 @@ public extension HUDRouter { func present(_ text: String, style: HUDMessageType = .default) { hudText = text self.style = style + isAutoHide = true isShowHud = true } + + func presentLoader(_ text: String = "Loading...", style: HUDMessageType = .default) { + hudText = text + self.style = style + isAutoHide = false + isShowHud = true + loaderStatus = .progress(nil) + } + + func hideLoader(style: HUDMessageType = .default, status: HUDLoaderStatus) { + hudText = "" + self.style = style + isAutoHide = true + isShowHud = false + loaderStatus = status + } } diff --git a/Sources/OversizeRouter/Router/Router.swift b/Sources/OversizeRouter/Router/Router.swift index 1d24024..51509c5 100644 --- a/Sources/OversizeRouter/Router/Router.swift +++ b/Sources/OversizeRouter/Router/Router.swift @@ -60,9 +60,7 @@ public extension Router { self.sheetWidth = sheetWidth self.sheet = sheet } - #else - func present(_ sheet: Destination, fullScreen: Bool = false) { if fullScreen { if fullScreenCover != nil { diff --git a/Sources/OversizeRouter/RoutingViews/RoutingSidebarView.swift b/Sources/OversizeRouter/RoutingViews/RoutingSidebarView.swift index c0d714c..a60d457 100644 --- a/Sources/OversizeRouter/RoutingViews/RoutingSidebarView.swift +++ b/Sources/OversizeRouter/RoutingViews/RoutingSidebarView.swift @@ -3,7 +3,6 @@ // RoutingSidebarView.swift, created on 17.08.2024 // -import OversizeServices import OversizeUI import SwiftUI @@ -30,7 +29,6 @@ public struct RoutingSidebarView: View where Tab: TabableView { .hud(hudRouter.hudText, isPresented: $hudRouter.isShowHud) } #else - tabView #endif } diff --git a/Sources/OversizeRouter/RoutingViews/RoutingSplitView.swift b/Sources/OversizeRouter/RoutingViews/RoutingSplitView.swift index 04a0839..8f87b0b 100644 --- a/Sources/OversizeRouter/RoutingViews/RoutingSplitView.swift +++ b/Sources/OversizeRouter/RoutingViews/RoutingSplitView.swift @@ -3,7 +3,6 @@ // RoutingSplitView.swift, created on 06.08.2024 // -import OversizeServices import SwiftUI public struct RoutingSplitView: View where Tab: TabableView, TopSidebar: View, BottomSidebar: View { @@ -37,14 +36,20 @@ public struct RoutingSplitView: View where Tab: public var body: some View { NavigationSplitView(columnVisibility: $navigationSplitViewVisibility) { - sidebar - .navigationSplitViewColumnWidth(200) + sidebar.navigationSplitViewColumnWidth( + min: 200, + ideal: 280, + max: 350 + ) + .environment(hudRouter) + .environment(router) } detail: { - router.selection.view() - .environment(router) + router.selection + .view() .environment(hudRouter) + .environment(router) } - .hud(hudRouter.hudText, isPresented: $hudRouter.isShowHud) + .hud(hudRouter.hudText, autoHide: hudRouter.isAutoHide, isPresented: $hudRouter.isShowHud) } private var sidebar: some View { @@ -81,6 +86,20 @@ public struct RoutingSplitView: View where Tab: bottomSidebar } .listStyle(.sidebar) + .toolbar { + ToolbarItemGroup { + Spacer() + + Button( + action: {}, + label: { + Image( + systemName: "plus.circle.fill" + ) + } + ) + } + } #endif } } diff --git a/Sources/OversizeRouter/RoutingViews/RoutingTabView.swift b/Sources/OversizeRouter/RoutingViews/RoutingTabView.swift index 578910a..b470372 100644 --- a/Sources/OversizeRouter/RoutingViews/RoutingTabView.swift +++ b/Sources/OversizeRouter/RoutingViews/RoutingTabView.swift @@ -3,7 +3,6 @@ // TabRoutingView.swift, created on 06.08.2024 // -import OversizeServices import OversizeUI import SwiftUI diff --git a/Sources/OversizeRouter/RoutingViews/RoutingView.swift b/Sources/OversizeRouter/RoutingViews/RoutingView.swift index d37c777..9174bfc 100644 --- a/Sources/OversizeRouter/RoutingViews/RoutingView.swift +++ b/Sources/OversizeRouter/RoutingViews/RoutingView.swift @@ -3,13 +3,11 @@ // RoutingView.swift, created on 28.07.2024 // -import OversizeServices import SwiftUI public struct RoutingView: View where Content: View, Destination: RoutableView { @State private var router: Router = .init() @State private var alertRouter: AlertRouter = .init() - @State private var hudRouter: HUDRouter = .init() private let content: () -> Content @@ -24,6 +22,7 @@ public struct RoutingView: View where Content: View, Desti destination.view() } } + .alert(item: $alertRouter.alert) { $0.alert } .sheet( item: $router.sheet, content: { sheet in @@ -34,23 +33,19 @@ public struct RoutingView: View where Content: View, Desti destination.view() } } + + #if os(macOS) + .frame( + width: router.sheetWidth, + height: router.sheetHeight + ) + #endif .presentationDetents(router.sheetDetents) .presentationDragIndicator(router.dragIndicator) .interactiveDismissDisabled(router.dismissDisabled) .alert(item: $alertRouter.alert) { $0.alert } - .systemServices() - .environment(router) - .environment(alertRouter) - .environment(hudRouter) - #if os(macOS) - .frame( - width: router.sheetWidth, - height: router.sheetHeight - ) - #endif } ) - #if os(iOS) .fullScreenCover(item: $router.fullScreenCover) { fullScreenCover in NavigationStack(path: $router.sheetPath) { @@ -61,16 +56,9 @@ public struct RoutingView: View where Content: View, Desti } } .alert(item: $alertRouter.alert) { $0.alert } - .systemServices() - .environment(router) - .environment(alertRouter) - .environment(hudRouter) } #endif - .alert(item: $alertRouter.alert) { $0.alert } - .systemServices() .environment(router) .environment(alertRouter) - .environment(hudRouter) } } diff --git a/Sources/OversizeRouter/SystemServices.swift b/Sources/OversizeRouter/SystemServices.swift deleted file mode 100644 index bde188f..0000000 --- a/Sources/OversizeRouter/SystemServices.swift +++ /dev/null @@ -1,83 +0,0 @@ -// -// Copyright © 2023 Alexander Romanov -// SystemServices.swift -// - -import Factory -import OversizeServices -import OversizeStoreService -import OversizeUI -import SwiftUI - -public struct SystemServicesModifier: ViewModifier { - @Injected(\.appStateService) private var appState: AppStateService - @Injected(\.settingsService) private var settingsService: SettingsServiceProtocol - @Injected(\.appStoreReviewService) private var appStoreReviewService: AppStoreReviewServiceProtocol - - @Environment(\.scenePhase) private var scenePhase: ScenePhase - @Environment(\.theme) private var theme: ThemeSettings - @AppStorage("AppState.PremiumState") private var isPremium: Bool = false - - @State private var blurRadius: CGFloat = 0 - @State private var oppacity: CGFloat = 1 - @State private var screnSize: ScreenSize = .init(width: 375, height: 667) - - enum FullScreenSheet: Identifiable, Equatable { - case onboarding - case payWall - case lockscreen - public var id: Int { - hashValue - } - } - - public init() {} - - public func body(content: Content) -> some View { - GeometryReader { geometry in - content - .onChange(of: scenePhase) { _, value in - switch value { - case .active: - if settingsService.blurMinimizeEnabend { - withAnimation { - blurRadius = 0 - } - } - case .background: - if settingsService.blurMinimizeEnabend { - withAnimation { - blurRadius = 10 - } - } - case .inactive: - if settingsService.blurMinimizeEnabend { - withAnimation { - blurRadius = 10 - } - } - @unknown default: - break - } - } - .onAppear { - let updatedScreenSize = ScreenSize(geometry: geometry) - screnSize = updatedScreenSize - } - .blur(radius: blurRadius) - .preferredColorScheme(theme.appearance.colorScheme) - .premiumStatus(isPremium) - .theme(ThemeSettings()) - .screenSize(screnSize) - #if os(iOS) - .accentColor(theme.accentColor) - #endif - } - } -} - -public extension View { - func systemServices() -> some View { - modifier(SystemServicesModifier()) - } -}