johnpatrickmorgan / FlowStacks

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

If you press routes.push more than three times, the view stack does not stack normally. #33

Closed dortus47 closed 2 years ago

dortus47 commented 2 years ago

https://user-images.githubusercontent.com/48409434/173030632-60cf36e6-f641-4389-b268-efa31668cea7.MP4

navitest.zip

I was using FlowStacks to create an app that pushes a new view every time I press a button. However, if the view stack is stacked more than three times using push several times, the view is not pushed normally and bounces out. How do we solve this?

import SwiftUI
import FlowStacks

enum AppScene {
    case home
    case map
    case mypage
    case setting
    case opensource
    case webview
}

struct AppCoordinator: View {
    @State var routes: Routes<AppScene>

    init(root: AppScene) {
        routes = [.root(root)]
    }

    var body: some View {
        Router($routes) { screen, _ in
            switch screen {

            case .home:
                HomeScreen()

            case .map:
                MapScreen()

            case .mypage:
                MyPageScreen(goSetting: {
                    routes.push(.setting)
                })

            case .setting:
                SettingScreen(goOpenSource: {
                    routes.push(.opensource)
                })

            case .opensource:
                OpenSourceScreen(goWebView: {
                    routes.push(.webview)
                })
            case .webview:
                WebViewScreen()
            }
        }
    }
}
johnpatrickmorgan commented 2 years ago

Thanks for raising this issue and providing example code.

When managing your own NavigationView you will need to set its navigationViewStyle to .stack. Otherwise there are some spurious binding updates that cause this issue.

dortus47 commented 2 years ago

I modified the code with the solution you told me, and I checked that it works normally. I didn't expect to get a reply so soon, but I was a little surprised. Thank you for creating a good library.