-
Notifications
You must be signed in to change notification settings - Fork 0
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
1 parent
3a4956c
commit 078ee88
Showing
13 changed files
with
332 additions
and
3 deletions.
There are no files selected for viewing
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,27 @@ | ||
name: CI | ||
|
||
on: | ||
push: | ||
branches: ["main"] | ||
workflow_dispatch: | ||
|
||
jobs: | ||
|
||
build-swiftpm: | ||
name: Build SwiftPM | ||
uses: oversizedev/GithubWorkflows/.github/workflows/build-swiftpm.yml@main | ||
with: | ||
package: "OversizeRouter" | ||
secrets: inherit | ||
|
||
# tests: | ||
# name: Test | ||
# needs: build-swiftpm | ||
# uses: oversizedev/GithubWorkflows/.github/workflows/test.yml@main | ||
# secrets: inherit | ||
|
||
bump: | ||
name: Bump version | ||
needs: build-swiftpm | ||
uses: oversizedev/GithubWorkflows/.github/workflows/bump.yml@main | ||
secrets: inherit |
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,16 @@ | ||
name: Release | ||
|
||
on: | ||
push: | ||
tags: | ||
- "*.*.*" | ||
|
||
jobs: | ||
build: | ||
name: Create release | ||
runs-on: ubuntu-latest | ||
steps: | ||
- name: Checkout | ||
uses: actions/checkout@v3 | ||
- name: Release | ||
uses: softprops/action-gh-release@v1 |
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,23 @@ | ||
// | ||
// Copyright © 2024 Alexander Romanov | ||
// AlertRouter.swift, created on 11.04.2024 | ||
// | ||
|
||
import Foundation | ||
|
||
public class AlertRouter<RootAlert: Alertable>: ObservableObject { | ||
// Alert | ||
@Published public var alert: RootAlert? = nil | ||
|
||
public init() {} | ||
} | ||
|
||
public extension AlertRouter { | ||
func present(_ alert: RootAlert) { | ||
self.alert = alert | ||
} | ||
|
||
func dismiss() { | ||
alert = nil | ||
} | ||
} |
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,30 @@ | ||
// | ||
// Copyright © 2024 Alexander Romanov | ||
// HUDRouter.swift, created on 14.04.2024 | ||
// | ||
|
||
import Foundation | ||
|
||
public enum HUDMessageType { | ||
case `default` | ||
case success | ||
case destructive | ||
case deleted | ||
case archived | ||
} | ||
|
||
public class HUDRouter: ObservableObject { | ||
@Published public var isShowHud: Bool = false | ||
@Published public var hudText: String = "" | ||
@Published public var type: HUDMessageType = .default | ||
|
||
public init() {} | ||
} | ||
|
||
public extension HUDRouter { | ||
func present(_ text: String, type: HUDMessageType = .default) { | ||
hudText = text | ||
self.type = type | ||
isShowHud = true | ||
} | ||
} |
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,23 @@ | ||
// | ||
// Copyright © 2024 Alexander Romanov | ||
// OversizeRouter.swift, created on 06.05.2024 | ||
// | ||
|
||
import Foundation | ||
|
||
public class MenuRouter<Menu: Menuble>: ObservableObject { | ||
@Published public var menu: Menu? | ||
@Published public var subMenu: Menu? | ||
|
||
public init(menu: Menu) { | ||
self.menu = menu | ||
} | ||
|
||
public func changeMenu(_ menu: Menu) { | ||
self.menu = menu | ||
} | ||
|
||
public func changeSubMenu(_ menu: Menu) { | ||
self.menu = menu | ||
} | ||
} |
This file was deleted.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
// | ||
// Copyright © 2024 Alexander Romanov | ||
// Alertable.swift, created on 14.04.2024 | ||
// | ||
|
||
import Foundation | ||
|
||
public protocol Alertable: Equatable, Hashable, Identifiable {} | ||
|
||
public extension Alertable { | ||
static func == (lhs: Self, rhs: Self) -> Bool { | ||
if lhs.id == rhs.id { | ||
true | ||
} else { | ||
false | ||
} | ||
} | ||
|
||
func hash(into hasher: inout Hasher) { | ||
hasher.combine(id) | ||
} | ||
} |
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,12 @@ | ||
// | ||
// Copyright © 2024 Alexander Romanov | ||
// File.swift, created on 06.05.2024 | ||
// | ||
|
||
public protocol Menuble: CaseIterable, Equatable, Identifiable {} | ||
|
||
public extension Menuble { | ||
func hash(into hasher: inout Hasher) { | ||
hasher.combine(id) | ||
} | ||
} |
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,22 @@ | ||
// | ||
// Copyright © 2024 Alexander Romanov | ||
// Routable.swift, created on 14.04.2024 | ||
// | ||
|
||
import SwiftUI | ||
|
||
public protocol Routable: Equatable, Hashable, Identifiable {} | ||
|
||
public extension Routable { | ||
func hash(into hasher: inout Hasher) { | ||
hasher.combine(id) | ||
} | ||
|
||
static func == (lhs: Self, rhs: Self) -> Bool { | ||
if lhs.id == rhs.id { | ||
true | ||
} else { | ||
false | ||
} | ||
} | ||
} |
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,14 @@ | ||
// | ||
// Copyright © 2024 Alexander Romanov | ||
// Tabable.swift, created on 14.04.2024 | ||
// | ||
|
||
import Foundation | ||
|
||
public protocol Tabable: CaseIterable, Equatable, Identifiable {} | ||
|
||
public extension Tabable { | ||
func hash(into hasher: inout Hasher) { | ||
hasher.combine(id) | ||
} | ||
} |
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,118 @@ | ||
// | ||
// Copyright © 2024 Alexander Romanov | ||
// Router.swift, created on 13.04.2024 | ||
// | ||
|
||
import SwiftUI | ||
|
||
@available(iOS 16.0, *) | ||
public final class Router<Destination: Routable>: ObservableObject { | ||
// Path | ||
@Published public var path = NavigationPath() | ||
@Published public var sheetPath = NavigationPath() | ||
@Published public var fullScreenCoverPath = NavigationPath() | ||
|
||
// Sheets | ||
@Published public var sheet: Destination? | ||
@Published public var fullScreenCover: Destination? | ||
@Published public var menu: Destination? | ||
@Published public var sheetDetents: Set<PresentationDetent> = [] | ||
@Published public var dragIndicator: Visibility = .hidden | ||
@Published public var dismissDisabled: Bool = false | ||
|
||
public init() {} | ||
} | ||
|
||
@available(iOS 16.0, *) | ||
public extension Router { | ||
func changeMenu(_ screen: Destination) { | ||
menu = screen | ||
} | ||
} | ||
|
||
@available(iOS 16.0, *) | ||
public extension Router { | ||
func move(_ screen: Destination) { | ||
path.append(screen) | ||
} | ||
|
||
func backToRoot() { | ||
path.removeLast(path.count) | ||
} | ||
|
||
func back(_ count: Int = 1) { | ||
let pathCount = path.count - count | ||
if pathCount > -1 { | ||
path.removeLast(count) | ||
} | ||
} | ||
} | ||
|
||
// MARK: - Sheets | ||
|
||
@available(iOS 16.0, *) | ||
public extension Router { | ||
func present(_ sheet: Destination, fullScreen: Bool = false) { | ||
if fullScreen { | ||
if fullScreenCover != nil { | ||
fullScreenCover = nil | ||
} | ||
fullScreenCover = sheet | ||
} else { | ||
restSheet() | ||
self.sheet = sheet | ||
} | ||
} | ||
|
||
func present(_ sheet: Destination, detents: Set<PresentationDetent> = [.large], indicator: Visibility = .hidden, dismissDisabled: Bool = false) { | ||
restSheet() | ||
sheetDetents = detents | ||
dragIndicator = indicator | ||
self.dismissDisabled = dismissDisabled | ||
self.sheet = sheet | ||
} | ||
|
||
func backOrDismiss() { | ||
if sheet != nil || fullScreenCover != nil { | ||
sheet = nil | ||
fullScreenCover = nil | ||
} else { | ||
back() | ||
} | ||
} | ||
|
||
func dismiss() { | ||
sheet = nil | ||
fullScreenCover = nil | ||
} | ||
|
||
func dismissSheet() { | ||
sheet = nil | ||
} | ||
|
||
func dismissFullScreenCover() { | ||
fullScreenCover = nil | ||
} | ||
|
||
func dismissDisabled(_ isDismissDisabled: Bool = true) { | ||
dismissDisabled = isDismissDisabled | ||
} | ||
|
||
private func restSheet() { | ||
if sheet != nil { | ||
sheet = nil | ||
} | ||
if fullScreenCover != nil { | ||
fullScreenCover = nil | ||
} | ||
if dragIndicator != .hidden { | ||
dragIndicator = .hidden | ||
} | ||
if dismissDisabled { | ||
dismissDisabled = false | ||
} | ||
if sheetDetents.isEmpty == false { | ||
sheetDetents = [] | ||
} | ||
} | ||
} |
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,18 @@ | ||
// | ||
// Copyright © 2024 Alexander Romanov | ||
// TabRouter.swift, created on 13.04.2024 | ||
// | ||
|
||
import Foundation | ||
|
||
public class TabRouter<Tab: Tabable>: ObservableObject { | ||
@Published public var tab: Tab | ||
|
||
public init(tab: Tab) { | ||
self.tab = tab | ||
} | ||
|
||
public func changeTab(_ tab: Tab) { | ||
self.tab = tab | ||
} | ||
} |