johnpatrickmorgan / FlowStacks

FlowStacks allows you to hoist SwiftUI navigation and presentation state into a Coordinator
MIT License
783 stars 56 forks source link

When using the popToRoot function, it appears that views are being dismissed one by one instead of directly navigating to the root view #71

Closed wahidtariq closed 5 months ago

wahidtariq commented 5 months ago

Steps to reproduce

Expected behavior

Actual behavior

Relevant code snippets:

struct ContentView: View {
    @EnvironmentObject var navigator: FlowNavigator<Screen>

    var body: some View {
      VStack {
        Button("View second") {
            navigator.push(.second)
        }
        Button("Go back to root") {
          navigator.goBackToRoot()
        }
      }
    }
}

struct ContentView2: View {

    @EnvironmentObject var navigator: FlowNavigator<Screen>

    var body: some View {
        VStack {
          Button("View third") {
              navigator.push(.third)
          }
          Button("Go back to root") {
              navigator.popToCurrentNavigationRoot()
          }
        }
    }
}

struct ContentView3: View {

    @EnvironmentObject var navigator: FlowNavigator<Screen>

    var body: some View {
        VStack {
          Button("Go back to root") {
            navigator.goBackToRoot()
          }
        }
    }
}

import FlowStacks

enum Screen {
  case first
  case second
  case third
}

struct AppCoordinator: View {

  @State var routes: Routes<Screen> = [.root(.first, embedInNavigationView: true)]

  var body: some View {
    Router($routes) { screen, _ in
      switch screen {
      case .first:
          ContentView()
      case .second:
          ContentView2()
      case .third:
          ContentView3()
      }
    }
  }

  private func showfirst() {
    routes.presentSheet(.first)
  }

  private func showsecond() {
    routes.push(.second)
  }

  private func goBack() {
    routes.goBack()
  }

  private func goBackToRoot() {
    routes.goBackToRoot()
  }
}

@main
struct flow_stackApp: App {
    var body: some Scene {
        WindowGroup {
            AppCoordinator()
        }
    }
}

Simulator Screen Recording - iPhone 15 Pro - 2024-02-07 at 20 31 42

wahidtariq commented 5 months ago

@johnpatrickmorgan

wahidtariq commented 5 months ago

if anyone else faces this issue downgrade 0.3.5 it works fine in that Tag