I have a regular SwiftUI View embedded inside of a NavigationStack. In this view, I make use of the .searchable()
view modifier to make that view searchable. I have a button on the toolbar placed on the .confirmationAction
section, which is a problem when a User types into the search bar and the button gets replaced by the SearchBar's cancel button.
Thus, I conditionally place the button, depending on whether a User is searching, either on the navigationBar or on the keyboard. The latter does not work however, as the button does not show and when trying to debug the View Hierarchy, Xcode throws an error saying the View Hierarchy could not be displayed. If I set the button to be on the .bottomBar
instead, it shows up perfectly and the View Hierarchy also displays with no further issue.
Has someone come across this issue and if so, how did you get it fixed?
Thank you in advance.
SwiftUI - Placing ToolbarItem on .keyboard does not work
The problem still exists. It seems that the toolbar becomes visible after the first submit.
I am also seeing a variety of this problem - the toolbar appears, but there's no content in the toolbar. Code is below but the TL;DR is the same as F99's response above, removing the Spacer() from the HStack fixes the problem
HStack {
TextField(store.prompt, text: $input)
.hideableToolbar(show: store.showToolbar) {
ToolbarItemGroup(placement: .keyboard) {
HStack {
ForEach(fastList) { item in
Button {
//
} label: {
Text("\(item.name)")
}
}
Spacer() // <–– COMMENTING OUT THIS LINE FIXES THE PROBLEM
}
}
}
}
}
ToolbarItem placement .keyboard for UITextView is not working. I had it in .bottombar and was working but now when keyboard appears the toolbar at the bottom disappears. So it does not work for both .bottombar and .keyboard for UITextView. .keyboard should work even for UITextView-UIRepresentableView as under the hood UIKit detects becomeFirstResonder(). So no idea why it is suddenly not working. So the only option is to use the input accessory view or have your own custom toolbar at the bottom which feels like back to beginning of SwiftUI.
Any news here @Vision Pro Engineer?
Any have a reliable workaround?
I'm able to reproduce the problem on iOS 18 using Xcode 16. Moving the app to the background and then switching back to it will make the tool bar appear.
Thank you!
Having a similar issue: FB15588827
same issue iOS 18