rundfunk47 / stinsen

Coordinators in SwiftUI. Simple, powerful and elegant.
MIT License
822 stars 87 forks source link

PopToRoot shows second view while transitioning from third to first view #104

Closed vveidi closed 1 year ago

vveidi commented 1 year ago

I have a coordinator and three screens:

@ViewBuilder
func makeStart() -> some View {
    TimetableView()
}

@ViewBuilder
func makeJoinMeeting() -> some View {
    JoinMeetingView()
}

@ViewBuilder
func makeMeeting() -> some View {
    MeetingView()
}

While on the third view I'm trying to .popToRoot in order to transition to the timetable. And sometimes the second view shows for a moment during the transition. Did anybody encounter this?

LePips commented 1 year ago

I observed this during my implementation: https://github.com/rundfunk47/stinsen/pull/77.

However it hasn't happened in my app even when pushing dozens of views. This is probably a quirk of NavigationView and may be helped when transitioned to the iOS 16 navigation APIs.

vveidi commented 1 year ago

I made a small project to reproduce the issue and uploaded it to my Github account here

Even on this simple app I still can reproduce the bug. Not every time but pretty consistently. I also noticed that when transition succeeds I got a message in the console, it says: 'NavigationLink presenting a value must appear inside a NavigationContent-based NavigationView. Link will be disabled.' But when (and only when) I got a buggy behavior, the console is crystal clear I don't know, but it seems like a bug to me. I also made a simple popToRoot example using native NavigationView (iOS14), and it works fine every time.

The video with the bug: https://user-images.githubusercontent.com/63232549/196788137-d06d1096-5a1b-4981-8df4-f362cb678676.mp4

@LePips Any ideas? What am I doing wrong?

LePips commented 1 year ago

1 - This also happens in the sample application so it's more easily reproducible there 2 - The navigation error in Xcode is from Stinsen still using NavigationView in iOS 16, which has new navigation APIs and deprecates NavigationView. Stinsen still needs to upgrade. 3 - This is just a quirk with NavigationView. I personally don't see it in my own apps and you are calling popToRoot() as expected.

There just isn't anything "wrong" going on here, just the system bugging out.

vveidi commented 1 year ago

@LePips Sadly, I face this issue 50/50 and it's a pretty frequent use case for my app. I still don't understand why simple (well, not very simple in a bigger app) native solution works as expected. Neither errors in the console, nor the bug. The code I found on stackoverflow ContentView.swift.zip

vveidi commented 1 year ago

@LePips @rundfunk47 Any ideas?

yektasarioglu commented 1 year ago

In my case, choosing push as PresentationType for a route caused this error on iOS 16 devices.

NavigationLink presenting a value must appear inside a NavigationContent-based NavigationView. Link will be disabled.