I'm trying to learn the basics of SwiftUI ( coming from UIKit ).
I'm simply trying to push a new View once my async call is finished, but I don't find how.
This is my test implementation :
struct MasterView: View {
@State var parralaxOffset: CGFloat = 0
func handleParralax(_ reader: GeometryProxy) -> some View {
self.parralaxOffset = reader.frame(in: .global).minY
return Text("Foreground contentOffset: \(reader.frame(in: .global).minY)")
}
var body: some View {
NavigationView {
Group {
Button(action: {
self.dummyAsynCall() {
//Push a new view
}
}) {
Text("Button")
}
}
}.navigationBarTitle("test")
}
private func dummyAsynCall(_ onComplete: @escaping (() -> ())) {
DispatchQueue.main.asyncAfter(deadline: .now() + .seconds(1)) {
print("Call completed")
onComplete()
}
}
}
I know about NavigationLink but they work synchronously (when a user taps it basically).
Does anyone know how to perform the navigation in the completion block ?