apple/SwiftUI, Combine

SwiftUI .swipeActions not working

lgvv 2024. 8. 28. 00:35

[SwiftUI] .swipeActions not working

 

When using swipeActions, it does not work if you place a other content instead of a Button.​

swipeActions interface

 

 

❌ It does not work

    @State private var showTranslation = false

    var body: some View {
        List(0..<5) {
            Text("\($0)")
                .swipeActions(edge: .trailing, allowsFullSwipe: true) {
                    Image(systemName: "plus") // ❌
                }
        }
        .listStyle(.plain)
        .translationPresentation(
            isPresented: $showTranslation,
            text: "테스트"
        )
    }
}

 

✅ It works

    @State private var showTranslation = false

    var body: some View {
        List(0..<5) {
            Text("\($0)")
                .swipeActions(edge: .trailing, allowsFullSwipe: true) {
                    // ✅
                    Button {
                        showTranslation.toggle()
                    } label: {
                        Image(systemName: "plus")
                    }
                }
        }
        .listStyle(.plain)
        .translationPresentation(
            isPresented: $showTranslation,
            text: "테스트"
        )
    }
}