I have a View 'B' that has an initialiser that takes an argument.
struct B: View {
let arg: Int
init(arg: Int) {
self.arg = arg
}
var body: some View {
Text("\(arg)")
}
}
And I have a Navigation View 'A'.
'A' has one button, which when pressed, shows a popup where the user picks a number from 1-5. A closure of type (Int) -> Void is called with the chosen number.
struct A: View {
@State var showPicker = false
var body: some View {
NavigationView {
Button(action: { self.showPicker = true }) {
Text("Pick Number")
}
.sheet(isPresented: self.$showPicker, content: {
NumberPicker { number in
*** Possible to navigate to B from here? ***
}
})
}
}
}
Question
Is it possible to initialise view B with the result from the closure, and then navigate to it?
This used to be possible with DynamicNavigationDestinationLink, however Apple deprecated it and stated in the release notes that NavigationLink contains its capabilities now. I have searched through the docs, however, I have not been able to figure out how to use NavigationLink to produce the same outcome.