I have a Tinder-like Vstack "card" that swipes left and right. The VStack contains an Image and a TextField below it. I want to drag the Image and have it drag the whole VStack, TextField included. It does that. However, the TextField also drags the whole VStack. I only want the Image to drag and have the textfield work as a textfield. Here is the code for the VStack.
return VStack {
VStack {
Image("food")
.resizable()
.aspectRatio(1.0, contentMode: .fit)
.clipShape(RoundedRectangle(cornerRadius: 50))
TextField("Leave a comment", text: $comment, onEditingChanged: { if $0 { self.kGuardian.showField = 0 } }) {
commentText = self.comment
}
.padding()
.background(GeometryGetter(rect: $kGuardian.rects[0]))
.background(Color(red: 239.0/255.0, green: 243.0/255.0, blue: 244.0/255.0, opacity: 1.0), cornerRadius: 10.0)
}
.padding()
.shadow(color: Color.black, radius: 15, x: 2, y: 2)
.offset(
x: viewState.width + dragState.translation.width
// y: viewState.height + dragState.translation.height
)
// .animation(.basic(duration: minimumLongPressDuration))
.gesture(longPressDrag)
.presentation($showAlert) {
Alert(title: Text("User commented on this photo!"), message: Text(commentText), primaryButton: .default(Text("OK")) {
commentText = ""
self.comment = ""
}, secondaryButton: .cancel()
)
}
// TextField("Leave a comment", text: $comment, onEditingChanged: { if $0 { self.kGuardian.showField = 0 } }) {
// commentText = self.comment
// }
// .padding()
// .background(GeometryGetter(rect: $kGuardian.rects[0]))
// .background(Color(red: 239.0/255.0, green: 243.0/255.0, blue: 244.0/255.0, opacity: 1.0), cornerRadius: 10.0)
}.offset(y: kGuardian.slide).animation(.basic(duration: 1.5))
.padding()
.shadow(color: Color.black, radius: 15, x: 2, y: 2)
}
}