JWAutumn / ACarousel

A carousel view for SwiftUI | SwiftUI 旋转木马效果
MIT License
406 stars 81 forks source link

Adding a NavigationLink prevent the item from being dragged #7

Open jfredsilva opened 3 years ago

jfredsilva commented 3 years ago

I added a Navigation link on the item in order to push a new view but by adding the navigation link (or a button) the swiping don't work anymore.

Any solution to have the item swipe and the navigation link on the item?

trouvainGregoire commented 3 years ago

I had the same issue.

I made this to solve it :


@State var activeMagazineID: Int? = nil

NavigationView{
            ACarousel(digitalMagazines) {
                magazine in
                VStack{
                    URLImage(magazine.thumbnail){
                        image in image.resizable()
                            .aspectRatio(contentMode: .fit)
                    }.cornerRadius(10)
                    Text(magazine.title)
                        .foregroundColor(.secondary)
                        .font(.subheadline)
                }
                .background(NavigationLink(
                    destination: MagazineView(magazine: magazine), tag: magazine.id, selection: $activeMagazineID){
                    EmptyView()
                })
                .onTapGesture {
                    activeMagazineID = magazine.id
                }
            }
        }