5

Given:

  1. SectionView as a row representation in a List
  2. Swipe actions associated with this view
  3. Tappable Image as a part of the same view

Required:

Display swipe actions on Image tap, not only using a swipe gesture.

Will be thankful for any clues regarding implementation.

struct SectionView: View {

@ObservedObject var viewModel: SectionVM

var body: some View {
    HStack {
        ...
        Image("iconVerticalDots") 
            .renderingMode(.template)
            .foregroundColor(AppColors.accent.asColor)
            .padding([.vertical, .leading], 4.0)
            .onTapGesture {
                //Show swipe actions
            }
    }
    .swipeActions {
        actions
    }
}

var actions: some View {
    ForEach(viewModel.menuTypes, id: \.name) { item in
        Button {
            print(item)
        } label: {
            VStack(spacing: 4.0) {
                item.icon
                    .map(Image.init)?
                    .resizable()
                    .frame(width: 16.0, height: 16.0)
                    .aspectRatio(contentMode: .fit)
                Text(item.name)
            }
        }
        .tint(item.background.asColor)
    }
}
  • Swipe Actions are great but difficult to discover. I would need to reveal the swipe action for tutorial purposes. Anton, did you ever find a solution? – Bogdan Balan Nov 24 '22 at 17:31

0 Answers0