Skip to content

Commit

Permalink
Simplifying internal navigation logic
Browse files Browse the repository at this point in the history
  • Loading branch information
kamaal111 committed Feb 28, 2024
1 parent b3f4645 commit accaf40
Show file tree
Hide file tree
Showing 6 changed files with 16 additions and 21 deletions.
10 changes: 10 additions & 0 deletions Example/Example.xcodeproj/xcshareddata/xcschemes/Example.xcscheme
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,16 @@
ReferencedContainer = "container:..">
</BuildableReference>
</TestableReference>
<TestableReference
skipped = "NO">
<BuildableReference
BuildableIdentifier = "primary"
BlueprintIdentifier = "KamaalCloudTests"
BuildableName = "KamaalCloudTests"
BlueprintName = "KamaalCloudTests"
ReferencedContainer = "container:..">
</BuildableReference>
</TestableReference>
</Testables>
</TestAction>
<LaunchAction
Expand Down
2 changes: 2 additions & 0 deletions Example/Example/Screens.swift
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@
import SwiftUI
import KamaalNavigation

typealias AppNavigator = Navigator<Screens>

enum Screens: Hashable, Codable, CaseIterable, NavigatorStackValue {
case home
case other
Expand Down
2 changes: 1 addition & 1 deletion Example/Example/Views/Screens/HomeScreen.swift
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ private let logger = KamaalLogger(from: HomeScreen.self)
struct HomeScreen: View {
@Environment(\.colorScheme) private var colorScheme

@EnvironmentObject private var navigator: Navigator<Screens>
@EnvironmentObject private var navigator: AppNavigator

@StateObject private var popUpManager = KPopUpManager()

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,24 +8,16 @@
import SwiftUI

public struct StackNavigationBackButton<Destination: NavigatorStackValue, Content: View>: View {
@Environment(\.presentationMode) private var presentationMode

@EnvironmentObject private var navigator: Navigator<Destination>

let content: () -> Content

public init(screenType _: Destination.Type, content: @escaping () -> Content) {
public init(screenType _: Destination.Type, @ViewBuilder content: @escaping () -> Content) {
self.content = content
}

public var body: some View {
Button(action: {
#if os(macOS)
self.navigator.goBack()
#else
self.presentationMode.wrappedValue.dismiss()
#endif
}) {
Button(action: { self.navigator.goBack() }) {
self.content()
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,7 @@ public struct StackNavigationChangeStackButton<Content: View, Destination: Navig
let destination: Destination
let content: () -> Content

public init(
destination: Destination,
@ViewBuilder content: @escaping () -> Content
) {
public init(destination: Destination, @ViewBuilder content: @escaping () -> Content) {
self.destination = destination
self.content = content
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,15 +19,9 @@ public struct StackNavigationLink<Content: View, Destination: NavigatorStackValu
}

public var body: some View {
#if os(macOS)
Button(action: { self.navigator.navigate(to: self.destination) }) {
self.content()
}
#else
NavigationLink(value: self.destination) {
self.content()
}
#endif
}
}

Expand Down

0 comments on commit accaf40

Please sign in to comment.