Skip to content

Commit 97d7164

Browse files
committed
SUMMARY:
1. Functionality improved 2. Access level bug fix 3. Example app included
1 parent 87f9fcd commit 97d7164

File tree

12 files changed

+863
-3
lines changed

12 files changed

+863
-3
lines changed

Example/AwesomeNavigationExample/AwesomeNavigationExample.xcodeproj/project.pbxproj

Lines changed: 586 additions & 0 deletions
Large diffs are not rendered by default.

Example/AwesomeNavigationExample/AwesomeNavigationExample.xcodeproj/project.xcworkspace/contents.xcworkspacedata

Lines changed: 7 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
{
2+
"colors" : [
3+
{
4+
"idiom" : "universal"
5+
}
6+
],
7+
"info" : {
8+
"author" : "xcode",
9+
"version" : 1
10+
}
11+
}
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
{
2+
"images" : [
3+
{
4+
"idiom" : "universal",
5+
"platform" : "ios",
6+
"size" : "1024x1024"
7+
},
8+
{
9+
"appearances" : [
10+
{
11+
"appearance" : "luminosity",
12+
"value" : "dark"
13+
}
14+
],
15+
"idiom" : "universal",
16+
"platform" : "ios",
17+
"size" : "1024x1024"
18+
},
19+
{
20+
"appearances" : [
21+
{
22+
"appearance" : "luminosity",
23+
"value" : "tinted"
24+
}
25+
],
26+
"idiom" : "universal",
27+
"platform" : "ios",
28+
"size" : "1024x1024"
29+
}
30+
],
31+
"info" : {
32+
"author" : "xcode",
33+
"version" : 1
34+
}
35+
}
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
{
2+
"info" : {
3+
"author" : "xcode",
4+
"version" : 1
5+
}
6+
}
Lines changed: 110 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,110 @@
1+
//
2+
// AwesomeNavigationExampleApp.swift
3+
// AwesomeNavigationExample
4+
//
5+
// Created by Arindam Karmakar on 05/06/25.
6+
//
7+
8+
import SwiftUI
9+
import AwesomeNavigation
10+
11+
@main
12+
struct AwesomeNavigationExampleApp: App {
13+
var body: some Scene {
14+
WindowGroup {
15+
let config = ANConfig(initialRoute: AppRoute.home) { route in
16+
switch route {
17+
case .home:
18+
HomeView()
19+
case .settings:
20+
SettingsView()
21+
case .item(let id):
22+
ItemView(id: id)
23+
}
24+
}
25+
26+
ANApplication(with: config)
27+
.preferredColorScheme(.dark)
28+
}
29+
}
30+
}
31+
32+
enum AppRoute: ANRoute {
33+
case home
34+
case settings
35+
case item(id: String)
36+
}
37+
38+
struct HomeView: View {
39+
@EnvironmentObject var nav: AwesomeNavigation
40+
41+
var body: some View {
42+
List {
43+
Section("PUSH") {
44+
Button("Push Settings View") {
45+
nav.push(AppRoute.settings)
46+
}
47+
48+
Button("Push Home View") {
49+
nav.push(AppRoute.home)
50+
}
51+
52+
Button("Push Item View") {
53+
nav.push(AppRoute.item(id: UUID().uuidString))
54+
}
55+
56+
Button("Push Settings View Replacing Current View") {
57+
nav.pushReplacement(AppRoute.settings)
58+
}
59+
}
60+
61+
Section("POP") {
62+
Button("Pop One View") {
63+
nav.pop()
64+
}
65+
66+
Button("Pop All Views") {
67+
nav.popToRoot()
68+
}
69+
}
70+
}
71+
.navigationTitle("Home")
72+
}
73+
}
74+
75+
struct SettingsView: View {
76+
@EnvironmentObject var nav: AwesomeNavigation
77+
78+
var body: some View {
79+
List {
80+
Section("PUSH") {
81+
Button("Push Home View Replacing Current View") {
82+
nav.pushReplacement(AppRoute.home)
83+
}
84+
}
85+
86+
Section("POP") {
87+
Button("Pop One View") {
88+
nav.pop()
89+
}
90+
91+
Button("Pop All Views") {
92+
nav.popToRoot()
93+
}
94+
}
95+
}
96+
.navigationTitle("Settings")
97+
}
98+
}
99+
100+
struct ItemView: View {
101+
let id: String
102+
103+
var body: some View {
104+
VStack {
105+
Text("Item ID: \(id)")
106+
}
107+
.padding()
108+
.navigationTitle("Item")
109+
}
110+
}
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
//
2+
// AwesomeNavigationExampleTests.swift
3+
// AwesomeNavigationExampleTests
4+
//
5+
// Created by Arindam Karmakar on 05/06/25.
6+
//
7+
8+
import Testing
9+
@testable import AwesomeNavigationExample
10+
11+
struct AwesomeNavigationExampleTests {
12+
13+
@Test func example() async throws {
14+
// Write your test here and use APIs like `#expect(...)` to check expected conditions.
15+
}
16+
17+
}
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
//
2+
// AwesomeNavigationExampleUITests.swift
3+
// AwesomeNavigationExampleUITests
4+
//
5+
// Created by Arindam Karmakar on 05/06/25.
6+
//
7+
8+
import XCTest
9+
10+
final class AwesomeNavigationExampleUITests: XCTestCase {
11+
12+
override func setUpWithError() throws {
13+
// Put setup code here. This method is called before the invocation of each test method in the class.
14+
15+
// In UI tests it is usually best to stop immediately when a failure occurs.
16+
continueAfterFailure = false
17+
18+
// In UI tests it’s important to set the initial state - such as interface orientation - required for your tests before they run. The setUp method is a good place to do this.
19+
}
20+
21+
override func tearDownWithError() throws {
22+
// Put teardown code here. This method is called after the invocation of each test method in the class.
23+
}
24+
25+
@MainActor
26+
func testExample() throws {
27+
// UI tests must launch the application that they test.
28+
let app = XCUIApplication()
29+
app.launch()
30+
31+
// Use XCTAssert and related functions to verify your tests produce the correct results.
32+
}
33+
34+
@MainActor
35+
func testLaunchPerformance() throws {
36+
// This measures how long it takes to launch your application.
37+
measure(metrics: [XCTApplicationLaunchMetric()]) {
38+
XCUIApplication().launch()
39+
}
40+
}
41+
}
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
//
2+
// AwesomeNavigationExampleUITestsLaunchTests.swift
3+
// AwesomeNavigationExampleUITests
4+
//
5+
// Created by Arindam Karmakar on 05/06/25.
6+
//
7+
8+
import XCTest
9+
10+
final class AwesomeNavigationExampleUITestsLaunchTests: XCTestCase {
11+
12+
override class var runsForEachTargetApplicationUIConfiguration: Bool {
13+
true
14+
}
15+
16+
override func setUpWithError() throws {
17+
continueAfterFailure = false
18+
}
19+
20+
@MainActor
21+
func testLaunch() throws {
22+
let app = XCUIApplication()
23+
app.launch()
24+
25+
// Insert steps here to perform after app launch but before taking a screenshot,
26+
// such as logging into a test account or navigating somewhere in the app
27+
28+
let attachment = XCTAttachment(screenshot: app.screenshot())
29+
attachment.name = "Launch Screen"
30+
attachment.lifetime = .keepAlways
31+
add(attachment)
32+
}
33+
}

Sources/AwesomeNavigation/AwesomeNavigation.swift

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,8 +40,12 @@ public final class AwesomeNavigation: ObservableObject {
4040
/// Replaces the current route with a new one.
4141
/// - Parameter route: The new route to be added, conforming to `ANRoute`.
4242
public func pushReplacement<R>(_ route: R) -> Void where R: ANRoute {
43-
self.pop(count: 1)
44-
self.push(route)
43+
if self.routeStack.count > 0 {
44+
self.pop(count: 1)
45+
self.push(route)
46+
} else {
47+
self.updateRoot(with: route)
48+
}
4549
}
4650

4751
/// Pops the topmost route from the navigation stack.

0 commit comments

Comments
 (0)