Skip to content

Commit

Permalink
Add new router
Browse files Browse the repository at this point in the history
  • Loading branch information
aromanov91 committed Apr 28, 2024
1 parent 430af61 commit 00bb1cc
Show file tree
Hide file tree
Showing 27 changed files with 504 additions and 396 deletions.
4 changes: 2 additions & 2 deletions Package.swift
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ let isProductionDependencies = ProcessInfo.processInfo.environment["RELEASE_DEPE
let package = Package(
name: "OversizeKit",
platforms: [
.iOS(.v15),
.iOS(.v16),
.macOS(.v13),
.tvOS(.v15),
.watchOS(.v9),
Expand Down Expand Up @@ -66,7 +66,7 @@ let package = Package(
.product(name: "OversizeModels", package: "OversizeModels"),
.product(name: "OversizeNetwork", package: "OversizeNetwork"),
.product(name: "Factory", package: "Factory"),
.product(name: "CachedAsyncImage", package: "swiftui-cached-async-image")
.product(name: "CachedAsyncImage", package: "swiftui-cached-async-image"),
]
),
.target(
Expand Down
29 changes: 13 additions & 16 deletions Sources/OversizeKit/LauncherKit/Launcher.swift
Original file line number Diff line number Diff line change
Expand Up @@ -49,30 +49,27 @@ public struct Launcher<Content: View, Onboarding: View>: View {
}
.onChange(of: scenePhase, perform: { value in
switch value {
case .active, .inactive:
break
case .background:
viewModel.authState = .locked
viewModel.pinCodeField = ""
@unknown default:
log("unknown")
default:
break
}
})
}

@ViewBuilder
var contentView: some View {
Group {
if viewModel.isShowSplashScreen {
SplashScreen()
} else if viewModel.isShowLockscreen {
lockscreenView
} else {
content
.onAppear {
viewModel.reviewService.launchEvent()
viewModel.launcherSheetsChek()
}
}
if viewModel.isShowSplashScreen {
SplashScreen()
} else if viewModel.isShowLockscreen {
lockscreenView
} else {
content
.onAppear {
viewModel.reviewService.launchEvent()
viewModel.launcherSheetsChek()
}
}
}

Expand Down
23 changes: 23 additions & 0 deletions Sources/OversizeKit/RouterKit/AlertRouter.swift
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
}
}
20 changes: 20 additions & 0 deletions Sources/OversizeKit/RouterKit/HUDRouter.swift
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
}
}
24 changes: 24 additions & 0 deletions Sources/OversizeKit/RouterKit/Protocols/Alertable.swift
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
}
}
}
16 changes: 16 additions & 0 deletions Sources/OversizeKit/RouterKit/Protocols/Routable.swift
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)
}
}
14 changes: 14 additions & 0 deletions Sources/OversizeKit/RouterKit/Protocols/Tabable.swift
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)
}
}
101 changes: 101 additions & 0 deletions Sources/OversizeKit/RouterKit/Router.swift
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 = []
}
}
}
18 changes: 18 additions & 0 deletions Sources/OversizeKit/RouterKit/TabRouter.swift
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
}
}
38 changes: 8 additions & 30 deletions Sources/OversizeKit/SettingsKit/Views/About/About/AboutView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,7 @@ import SwiftUI
import MessageUI

public struct AboutView: View {
@Environment(\.verticalSizeClass) private var verticalSizeClass
@Environment(\.isPortrait) var isPortrait
@Environment(\.presentationMode) var presentationMode
@Environment(\.settingsNavigate) var settingsNavigate
@Environment(\.screenSize) var screenSize
@Environment(\.iconStyle) var iconStyle: IconStyle

Expand All @@ -34,9 +32,6 @@ import SwiftUI
@State var isSharePresented = false
@State private var isShowMail = false

@State var isShowPrivacy = false
@State var isShowTerms = false

@State private var isPresentStoreProduct: Bool = false

var isLargeScreen: Bool {
Expand Down Expand Up @@ -69,23 +64,13 @@ import SwiftUI

public var body: some View {
#if os(iOS)
PageView(L10n.Settings.about, onOffsetChanged: { offset = $0 }) {
Page(L10n.Settings.about) {
list
.surfaceContentRowMargins()
.task {
await viewModel.fetchApps()
}
}
.leadingBar {
/*
if !isPortrait, verticalSizeClass == .regular {
EmptyView()
} else {
BarButton(.back)
}
*/
BarButton(.back)
}
.backgroundSecondary()

#else
Expand Down Expand Up @@ -282,27 +267,20 @@ import SwiftUI

SectionView {
VStack(spacing: .zero) {
NavigationLink(destination: OurResorsesView()) {
Row("Our open resources")
.rowArrow()
Row("Our open resources") {
settingsNavigate(.move(.ourResorses))
}
.buttonStyle(.row)
.rowArrow()

if let privacyUrl = Info.url.appPrivacyPolicyUrl {
Row(L10n.Store.privacyPolicy) {
isShowPrivacy.toggle()
}
.sheet(isPresented: $isShowPrivacy) {
WebView(url: privacyUrl)
settingsNavigate(.present(.webView(url: privacyUrl)))
}
}

if let termsOfUde = Info.url.appTermsOfUseUrl {
Row(L10n.Store.termsOfUse) {
isShowTerms.toggle()
}
.sheet(isPresented: $isShowTerms) {
WebView(url: termsOfUde)
settingsNavigate(.present(.webView(url: termsOfUde)))
}
}
}
Expand Down Expand Up @@ -491,7 +469,7 @@ import SwiftUI
let appName = Info.app.name,
let appBuild = Info.app.build
{
Text("© 2023 \(developerName). \(appName) \(appVersion) (\(appBuild))")
Text("© 2024 \(developerName). \(appName) \(appVersion) (\(appBuild))")
.footnote()
.foregroundColor(.onBackgroundDisabled)
} else {
Expand Down
Loading

0 comments on commit 00bb1cc

Please sign in to comment.