fermoya / SwiftUIPager

Native Pager in SwiftUI
MIT License
1.3k stars 172 forks source link

[BUG] NavigationLink not works if use List #250

Closed bfreeTax closed 2 years ago

bfreeTax commented 2 years ago

Describe the bug NavigationLink stops working if using List and use loopPages false

To Reproduce

Expected behavior It Should works as it works using VStack.

Screenshots / Videos If applicable, add screenshots to help explain your problem.

Environment:

Additional context Console shows this error: SwiftUI encountered an issue when pushing aNavigationLink. Please file a bug.

fermoya commented 2 years ago

Weird, do you really need to use a GeometryReader there? Sometimes they give trouble and Pager already contains one. Have you tried removing it?

fermoya commented 2 years ago

Closing, this seems a SwiftUI issue

samuelbradshaw commented 2 years ago

I was able to get my implementation working by hiding the NavigationLink in the background of a button, similar to the second example here. I also added .buttonStyle(.plain), which prevents the button action from bubbling up to the list row – this allows you to have multiple buttons and/or NavigationLinks in the same row. Hopefully this helps someone:

Button {
    isActive = true
} label: {
    rowDetails.background(
        NavigationLink(destination: detailsPage, isActive: $isActive) {
            EmptyView()
        }
        .opacity(0.0)
    )
}
.buttonStyle(.plain)