-
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
430af61
commit 00bb1cc
Showing
27 changed files
with
504 additions
and
396 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
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,20 @@ | ||
// | ||
// Copyright © 2024 Alexander Romanov | ||
// HUDRouter.swift, created on 14.04.2024 | ||
// | ||
|
||
import Foundation | ||
|
||
public class HUDRouter: ObservableObject { | ||
@Published public var isShowHud: Bool = false | ||
@Published public var hudText: String = "" | ||
|
||
public init() {} | ||
} | ||
|
||
public extension HUDRouter { | ||
func present(_ text: String) { | ||
hudText = text | ||
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,24 @@ | ||
// | ||
// Copyright © 2024 Alexander Romanov | ||
// Alertable.swift, created on 14.04.2024 | ||
// | ||
|
||
import Foundation | ||
|
||
public protocol Alertable: Equatable, Hashable, Identifiable {} | ||
|
||
public extension Alertable { | ||
var id: Self { self } | ||
|
||
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,16 @@ | ||
// | ||
// Copyright © 2024 Alexander Romanov | ||
// Routable.swift, created on 14.04.2024 | ||
// | ||
|
||
import SwiftUI | ||
|
||
public protocol Routable: Equatable, Hashable, Identifiable {} | ||
|
||
public extension Routable { | ||
var id: Self { self } | ||
|
||
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,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,101 @@ | ||
// | ||
// 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 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 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 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 | ||
} | ||
} |
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.