Skip to content

Commit

Permalink
🔥 (Navigation): Remove print(), cleanup, format
Browse files Browse the repository at this point in the history
  • Loading branch information
ladislas committed Dec 2, 2023
1 parent 4ddab24 commit ad86d45
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 23 deletions.
4 changes: 2 additions & 2 deletions Examples/iOSApp/Sources/HomeView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@ struct HomeView: View {

var body: some View {
VStack {
Text( /*@START_MENU_TOKEN@*/"Hello, World!" /*@END_MENU_TOKEN@*/)
.font(.largeTitle)
Text("Try programmatic navigation")
.font(.headline)

Button("Go to Activities / Activity 1") {
navigation.set(path: Activity.all[0], for: .activities)
Expand Down
26 changes: 5 additions & 21 deletions Examples/iOSApp/Sources/Navigation.swift
Original file line number Diff line number Diff line change
Expand Up @@ -30,10 +30,8 @@ class Navigation: ObservableObject {
var selectedCategory: Category? = .home {
willSet {
disableUICompletly = true
guard !isProgrammaticNavigation else {
print("isProgrammaticNavigation is true, early return to avoid reseting path")
return // ? Note: early return to avoid reseting path
}
// ? Note: early return to avoid reseting path
guard !isProgrammaticNavigation else { return }
backupPath(for: selectedCategory)
}
didSet {
Expand Down Expand Up @@ -67,22 +65,18 @@ class Navigation: ObservableObject {
withTransaction(pushPopNoAnimationTransaction) {
homeNavPathBackup = path
}
print("backup homeNavPathBackup: \(homeNavPathBackup)")

case .activities:
withTransaction(pushPopNoAnimationTransaction) {
activitiesNavPathBackup = path
}
print("backup activitiesNavPathBackup: \(activitiesNavPathBackup)")

case .curriculums:
withTransaction(pushPopNoAnimationTransaction) {
curriculumsNavPathBackup = path
}
print("backup curriculumsNavPathBackup: \(curriculumsNavPathBackup)")

case .none:
print("category is nil, early return to avoid reseting path")
return // ? Note: early return to avoid reseting path
}

Expand All @@ -97,48 +91,41 @@ class Navigation: ObservableObject {
withTransaction(pushPopNoAnimationTransaction) {
path = homeNavPathBackup
}
print("restore homeNavPath: \(path)")

case .activities:
withTransaction(pushPopNoAnimationTransaction) {
path = activitiesNavPathBackup
}
print("restore activitiesNavPath: \(path)")

case .curriculums:
withTransaction(pushPopNoAnimationTransaction) {
path = curriculumsNavPathBackup
}
print("restore curriculumsNavPath: \(path)")

case .none:
print("category is nil, no retore")
break
}
}

func set(path newPath: AnyHashable..., for newCategory: Category) {
switch newCategory {
case .home:
break

case .activities:
activitiesNavPathBackup = newPath.compactMap { $0 as? Activity }
.reduce(into: NavigationPath()) { $0.append($1) }

case .curriculums:
var localPath = NavigationPath()
newPath.forEach {
if let activity = $0 as? Activity {
print("append activity: \(activity)")
localPath.append(activity)
} else if let curriculum = $0 as? Curriculum {
print("append curriculum: \(curriculum)")
localPath.append(curriculum)
} else {
print("append unknown: \($0)")
}
}
print("localPath: \(localPath)")
curriculumsNavPathBackup = localPath
print("bckupPath: \(curriculumsNavPathBackup)")
}

underProgrammaticNavigation {
Expand Down Expand Up @@ -166,9 +153,6 @@ class Navigation: ObservableObject {
guard let curriculum = Curriculum.all.first(where: { $0.id == curriculum }) else { return }
guard let activity = curriculum.activities.first(where: { $0.id == id }) else { return }

print("curri: \(curriculum)")
print("activ: \(activity)")

var localPath = NavigationPath()

localPath.append(curriculum)
Expand Down

0 comments on commit ad86d45

Please sign in to comment.