Skip to content

Commit

Permalink
Ci (#2)
Browse files Browse the repository at this point in the history
* Upd ci

* Upd

* Update ci.yml

* Update ci.yml

* Fix dependencies

* Fix tvOS

* Upd

* Fix alert router

* Up to Swift6
  • Loading branch information
aromanov91 authored Nov 9, 2024
1 parent 284aa09 commit 1cfdc31
Show file tree
Hide file tree
Showing 12 changed files with 108 additions and 157 deletions.
10 changes: 2 additions & 8 deletions Package.swift
Original file line number Diff line number Diff line change
@@ -1,23 +1,20 @@
// 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
import PackageDescription
import Foundation

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
Expand Down Expand Up @@ -45,10 +42,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"),
]
Expand Down
2 changes: 1 addition & 1 deletion Sources/OversizeRouter/Protocols/Alertable.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
4 changes: 2 additions & 2 deletions Sources/OversizeRouter/Protocols/Routable.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
10 changes: 5 additions & 5 deletions Sources/OversizeRouter/Protocols/Tabable.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
16 changes: 13 additions & 3 deletions Sources/OversizeRouter/Router/Alert/AlertResolve.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
Expand All @@ -21,6 +22,8 @@ public extension AppAlert {
"dismiss"
case .delete:
"delete"
case .unsavedChanges:
"unsavedChanges"
case .appError:
"appError"
case .text:
Expand All @@ -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):
Expand Down
27 changes: 26 additions & 1 deletion Sources/OversizeRouter/Router/HUDRouter.swift
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

import Foundation

public enum HUDMessageType {
public enum HUDMessageType: Sendable {
case `default`
case success
case destructive
Expand All @@ -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() {}
}
Expand All @@ -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
}
}
2 changes: 0 additions & 2 deletions Sources/OversizeRouter/Router/Router.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
22 changes: 10 additions & 12 deletions Sources/OversizeRouter/RoutingViews/RoutingSidebarView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
// RoutingSidebarView.swift, created on 17.08.2024
//

import OversizeServices
import OversizeUI
import SwiftUI

Expand All @@ -21,20 +20,19 @@ public struct RoutingSidebarView<Tab>: View where Tab: TabableView {

public var body: some View {
#if os(iOS) || os(macOS) || os(tvOS) || os(visionOS)
if #available(iOS 18.0, macOS 15.0, tvOS 18.0, visionOS 2.0, *) {
tabView
.tabViewStyle(.sidebarAdaptable)
.hud(hudRouter.hudText, isPresented: $hudRouter.isShowHud)
} else {
tabView
.hud(hudRouter.hudText, isPresented: $hudRouter.isShowHud)
}
if #available(iOS 18.0, macOS 15.0, tvOS 18.0, visionOS 2.0, *) {
tabView
.tabViewStyle(.sidebarAdaptable)
.hud(hudRouter.hudText, isPresented: $hudRouter.isShowHud)
} else {
tabView
.hud(hudRouter.hudText, isPresented: $hudRouter.isShowHud)
}
#else

tabView
tabView
#endif
}

var tabView: some View {
TabView(selection: $router.selection) {
ForEach(router.tabs) { tab in
Expand Down
41 changes: 30 additions & 11 deletions Sources/OversizeRouter/RoutingViews/RoutingSplitView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
// RoutingSplitView.swift, created on 06.08.2024
//

import OversizeServices
import SwiftUI

public struct RoutingSplitView<TopSidebar, BottomSidebar, Tab>: View where Tab: TabableView, TopSidebar: View, BottomSidebar: View {
Expand Down Expand Up @@ -37,14 +36,20 @@ public struct RoutingSplitView<TopSidebar, BottomSidebar, Tab>: 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 {
Expand All @@ -58,13 +63,13 @@ public struct RoutingSplitView<TopSidebar, BottomSidebar, Tab>: View where Tab:
}
.listStyle(.sidebar)
#elseif os(watchOS) || os(tvOS)
List {
ForEach(router.tabs) { menu in
NavigationLink(value: menu) {
Text(menu.title)
List {
ForEach(router.tabs) { menu in
NavigationLink(value: menu) {
Text(menu.title)
}
}
}
}
#else
List(selection: $router.selection) {
topSidebar
Expand All @@ -81,6 +86,20 @@ public struct RoutingSplitView<TopSidebar, BottomSidebar, Tab>: View where Tab:
bottomSidebar
}
.listStyle(.sidebar)
.toolbar {
ToolbarItemGroup {
Spacer()

Button(
action: {},
label: {
Image(
systemName: "plus.circle.fill"
)
}
)
}
}
#endif
}
}
Expand Down
1 change: 0 additions & 1 deletion Sources/OversizeRouter/RoutingViews/RoutingTabView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
// TabRoutingView.swift, created on 06.08.2024
//

import OversizeServices
import OversizeUI
import SwiftUI

Expand Down
47 changes: 19 additions & 28 deletions Sources/OversizeRouter/RoutingViews/RoutingView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,11 @@
// RoutingView.swift, created on 28.07.2024
//

import OversizeServices
import SwiftUI

public struct RoutingView<Content, Destination>: View where Content: View, Destination: RoutableView {
@State private var router: Router<Destination> = .init()
@State private var alertRouter: AlertRouter = .init()
@State private var hudRouter: HUDRouter = .init()

private let content: () -> Content

Expand All @@ -24,6 +22,7 @@ public struct RoutingView<Content, Destination>: View where Content: View, Desti
destination.view()
}
}
.alert(item: $alertRouter.alert) { $0.alert }
.sheet(
item: $router.sheet,
content: { sheet in
Expand All @@ -35,39 +34,31 @@ public struct RoutingView<Content, Destination>: View where Content: View, Desti
}
}

#if os(macOS)
.frame(
width: router.sheetWidth,
height: router.sheetHeight
)
#endif
.presentationDetents(router.sheetDetents)
.presentationDragIndicator(router.dragIndicator)
.interactiveDismissDisabled(router.dismissDisabled)
.systemServices()
.environment(router)
.environment(alertRouter)
.environment(hudRouter)
#if os(macOS)
.frame(
width: router.sheetWidth,
height: router.sheetHeight
)
#endif
.alert(item: $alertRouter.alert) { $0.alert }
}
)
.systemServices()
.environment(router)
.environment(alertRouter)
.environment(hudRouter)
#if os(iOS)
.fullScreenCover(item: $router.fullScreenCover) { fullScreenCover in
NavigationStack(path: $router.sheetPath) {
fullScreenCover
.view()
.navigationDestination(for: Destination.self) { destination in
destination.view()
}
}
.systemServices()
.environment(router)
.environment(alertRouter)
.environment(hudRouter)
.fullScreenCover(item: $router.fullScreenCover) { fullScreenCover in
NavigationStack(path: $router.sheetPath) {
fullScreenCover
.view()
.navigationDestination(for: Destination.self) { destination in
destination.view()
}
}
.alert(item: $alertRouter.alert) { $0.alert }
}
#endif
.environment(router)
.environment(alertRouter)
}
}
Loading

0 comments on commit 1cfdc31

Please sign in to comment.