fatbobman/SwipeCell

Navigation Link swipe does not work

Patresko opened this issue · 5 comments

ScrollView(.vertical, showsIndicators: false) {
LazyVStack(alignment: .leading) { NavigationLink(destination: LiftDetail(lift: lift, categoryID: category.id) .environmentObject(localization) ){ Lift( title: getText(liftObj: lift, language: localization.primaryLanguage).code, description: getText(liftObj: lift, language: localization.primaryLanguage).title, img: getText(liftObj: lift, language: localization.primaryLanguage).photoId ) .id(UUID()) } .frame(height:80) .swipeCell(cellPosition: .both, leftSlot:slot1, rightSlot: slot1) .dismissSwipeCellForScrollViewForLazyVStack() } }

I have code like this but swiping does not trigger at all

When using button or Navigationlink as cell, SwipeCell will not tiger
You can use code similar to the following to complete the view navigation

//
//  Test.swift
//  SwiftUIX_Test
//
//  Created by Yang Xu on 2021/5/28.
//

import Foundation
import SwiftUI
import SwipeCell

struct NavigationLinkTest:View{
    @State var id:Int = 0
    @State var go:Bool = false
    var body: some View{
        NavigationView{
            ZStack{
                NavigationLink("", destination: Text("\(id)"), isActive: $go)
                    .frame(width: 0,height: 0)
                ScrollView{
                    LazyVStack{
                        ForEach(0..<10){ i in
                            let button = SwipeCellButton(
                                buttonStyle: .titleAndImage,
                                title: "New",
                                systemImage: "plus.square",
                                view: nil,
                                backgroundColor: .blue,
                                action: {
                                    id = i  // set destination info
                                    go.toggle()  //tigger here
                                }
                            )

                            let slot = SwipeCellSlot(slots: [button])

                            cell(i)
                                .swipeCell(cellPosition: .right, leftSlot: nil, rightSlot: slot)
                        }
                    }
                }
            }
            .navigationTitle("NavigationLink Test")
        }
    }

    func cell(_ i:Int) -> some View{
        VStack{
            Text("id:\(i)")
        }
        .padding(.horizontal)
        .frame(height: 100)
    }
}

onTapGesture may be a better way

Can someone elaborate on the onTapGesture ?
I have a custom View that I use as cells in ScrollView, now that cell has swipeCell modifier. When I wrap the cell in navigationLink, it shows that tap gesture when cell is tapped but nothings happening. If I remove the swipe cell modifier im in the game. But I guess the drag gesture recogniser in swipe cell api is invalidated notification about onTap ?

ScrollView {
            LazyVStack {
                ForEach(lists, id: \.self) { item in
                    Text("Swipe in scrollView:\(item)") // cell
                        .onTapGesture {   // add onTap at cell to trigger navigationLink
                            i = item
                            DispatchQueue.main.asyncAfter(deadline: .now() + 0.1){
                                go.toggle()
                            }
                        }
                        .frame(height: 80)
                        .swipeCell(cellPosition: .both, leftSlot: slot, rightSlot: slot)
                        .dismissSwipeCellForScrollViewForLazyVStack()
                }
            }
        }
        .background(
            NavigationLink("", destination: Text("\(i)"), isActive: $go)
                .frame(width:0,height:0)
        )

For newer code you'll have to push to the navigation stack since NavigationLink with isActive is deprecated.