In my code, I have a Search Bar on the top that have a "magnifyingglass" inside a circle as a button. When I click it, it shows a textfield, and then I have to press it to open the keyboard. What do I need to implement in the code so that when I click on the "magnifyingglass" image it immediately opens the keyboard, without having to press it again?
VStack(spacing: 0) {
HStack{
if !self.show{
Text("Buscar")
.fontWeight(.bold)
.font(.title)
.foregroundColor(.white)
}
Spacer(minLength: 0)
HStack{
if self.show{
Image(systemName: "magnifyingglass")
.padding(.leading, 5)
TextField("Buscar", text: self.$txt)
Button(action: {
withAnimation {
self.txt = ""
self.show.toggle()
}
}) {
Image(systemName: "xmark").foregroundColor(.black)
}
.padding(.horizontal, 8)
}
else{
Button(action: {
withAnimation {
self.show.toggle()
}
}) {
Image(systemName:"magnifyingglass")
.resizable()
.frame(width: 22, height: 22)
.font(Font.system(.body).bold())
.foregroundColor(.black)
.padding(10)
}
}
}
.padding(self.show ? 10 : 0)
.background(Color.white)
.cornerRadius(90)
}
.padding(.top, UIApplication.shared.windows.first?.safeAreaInsets.top == 0 ? 0 : UIApplication.shared.windows.first?.safeAreaInsets.top)
.padding(.horizontal)
.padding(.bottom , 10)
.background(Color("Color"))