ios – SwiftUI 4 NavigationStack Append View in navigationDestination fail
[ad_1]
I used to be making an attempt the brand new NavigationStack in swiftUI 4 and I discovered an attention-grabbing downside
If I created a view like that
RootView()
.navigationDestination(for: Route.self, vacation spot: { route in
NavigationBarContainerView {
ViewRouter().routeToView(with: route)
}.toolbar(.hidden)
})
Then I appended a routing Path to it
Routing.shared.appendPath(.confirmEmail)
then contained in the perform routeToView .. I appended one other path
@ViewBuilder
func routeToView(with route: Route) -> some View {
swap route {
case .confirmEmail:
Textual content("2")
.onAppear {
Routing.shared.appendPath(.passwordRecovery)
}
case .passwordRecovery:
PasswordRecovery()
default:
EmptyView()
}
}
my Routing is solely
public class Routing: ObservableObject {
public static let shared = Routing()
@Revealed public var path: NavigationPath = NavigationPath()
personal init() {}
public func appendPath(_ route: Route) {
DispatchQueue.important.async {
self.path.append(route)
}
}
public func popToRoot() {
path = NavigationPath()
}
}
it by no means exhibits the password restoration display. I Thought it is form of race situation, since it really works effective if i add a delayer or sleep. however I attempted to append two routes on the beginning, it really works effective..
My guess that the navigationDestination would not re-evaluate the view until the navigation Path totally established.
However I am unable to determine tips on how to come over such problem
[ad_2]