Skip to content

Commit

Permalink
Adds save and restore path to ArrayBindingView
Browse files Browse the repository at this point in the history
  • Loading branch information
johnpatrickmorgan committed Jul 30, 2022
1 parent 66e2990 commit 01bfad3
Showing 1 changed file with 32 additions and 12 deletions.
44 changes: 32 additions & 12 deletions NavigationBackportApp/Shared/ArrayBindingView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -8,21 +8,41 @@ enum Screen: Hashable {
}

struct ArrayBindingView: View {
@State var savedPath: [Screen]?
@State var path: [Screen] = []

var body: some View {
NBNavigationStack(path: $path) {
HomeView(show99RedBalloons: show99RedBalloons)
.nbNavigationDestination(for: Screen.self, destination: { screen in
switch screen {
case .numberList(let numberList):
NumberListView(numberList: numberList)
case .number(let number):
NumberView(number: number, goBackToRoot: { path.removeLast(path.count) })
case .visualisation(let visualisation):
EmojiView(visualisation: visualisation)
}
})
VStack {
HStack {
Button("Save", action: savePath)
.disabled(savedPath == path)
Button("Restore", action: restorePath)
.disabled(savedPath == nil)
}
NBNavigationStack(path: $path) {
HomeView(show99RedBalloons: show99RedBalloons)
.nbNavigationDestination(for: Screen.self, destination: { screen in
switch screen {
case .numberList(let numberList):
NumberListView(numberList: numberList)
case .number(let number):
NumberView(number: number, goBackToRoot: { path.removeLast(path.count) })
case .visualisation(let visualisation):
EmojiView(visualisation: visualisation)
}
})
}
}
}

func savePath() {
savedPath = path
}

func restorePath() {
guard let savedPath = savedPath else { return }
$path.withDelaysIfUnsupported {
$0 = savedPath
}
}

Expand Down

0 comments on commit 01bfad3

Please sign in to comment.