I currently have the following code that represents a TextField with a background and an icon.
struct TextFieldAreaView: View {
@State var query = ""
var body: some View {
HStack {
Image(systemName: "magnifyingglass")
.padding(.leading, 10)
TextField("Placeholder", text: $query)
.padding(5)
}
.background(Color.black.opacity(0.3))
.cornerRadius(10)
.padding()
}
}
Of course, because the background is actually a HStack and the icon an image outside the TextField's frame area, when the user taps on either of those, the keyboard won't show up.
In order for the keyboard to show you must precisely tap on the TextField. This of course is not very intuitive.
Is there any way to make it so that when tapping on the icon or the background HStack the keyboard would show up?