Tenho um aplicativo SwiftUI que exibe um feed social com posts em uma Lista. Cada post contém botões que precisam permanecer interativos, mas não quero que a célula inteira seja tocável.
Tentei diferentes abordagens, como .disabled(true) na lista (que também desabilita os botões), .allowsHitTesting(false) em elementos individuais e .onTapGesture {} para absorver toques, mas nenhuma funciona como esperado.
Obrigado
List() {
ForEach(posts, id: \.self) { post in
PostView()
.onAppear {
if post == posts.last {
loadMorePost()
}
}
.listRowInsets(EdgeInsets())
.alignmentGuide(.listRowSeparatorLeading) { vd in
return 0
}
}
}
.listStyle(.plain)
struct PostView: View {
var body: some View {
VStack(spacing: 10) {
PostHeaderView(image: Image("clovis"), userName: "Stephane", userIdentifier: "stephane_")
PostContentView()
}
.padding(20)
}
}
struct PostContentView: View {
var body: some View {
VStack(alignment: .leading, spacing: 10) {
// Post content
Text("Coiffeuse")
.font(.headline)
Text("It is a long established fact that a reader will be distracted...")
.font(.caption)
HStack(spacing: 20) {
PriceContainerView()
Spacer()
HStack(spacing: 2) {
Image(systemName: "eyes")
Text("2K")
}
// This button needs to remain interactive
Button(action: { print("Save To Later") }) {
Image(systemName: "bookmark")
.foregroundStyle(.mediumGray)
}
}
}
}
}
```