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 fascinating 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 operate routeToView .. I appended one other path

@ViewBuilder
func routeToView(with route: Route) -> some View {
   change route {

      case .confirmEmail:
       Textual content("2")
        .onAppear {
            Routing.shared.appendPath(.passwordRecovery)
         }
       case .passwordRecovery:
          PasswordRecovery()

        
    default:
        EmptyView()
   }
}

my Routing is just

public class Routing: ObservableObject {
public static let shared = Routing()
@Revealed public var path: NavigationPath = NavigationPath()
non-public init() {}

public func appendPath(_ route: Route) {
    DispatchQueue.major.async {
        self.path.append(route)
    }
}

public func popToRoot() {
    path = NavigationPath()
}

}

it by no means reveals the password restoration display. I Thought it is sort of race situation, since it really works high quality if i add a delayer or sleep. however I attempted to append two routes on the beginning, it really works high quality..

My guess that the navigationDestination does not re-evaluate the view until the navigation Path totally established.
However I can not work out come over such subject

[ad_2]

Leave a Reply