struct ContentView: View {
@State var isPresented = false
var body: some View {
Button {
isPresented.toggle()
} label: {
Text("Button")
}
.sheet(isPresented: $isPresented) {
SubView()
}
}
}
struct SubView: View {
@State var text = ""
var body: some View {
NavigationStack {
TextEditor(text: $text)
.toolbar {
ToolbarItemGroup(placement: .bottomBar) {
Button("Click") {
}
}
ToolbarItemGroup(placement: .keyboard) {
Button("Click") {
}
}
}
}
}
}
ToolbarItemGroup(placement: .keyboard) is not showed with Sheet
I'm seeing this exact same issue. I haven't had success getting this to run at all. And its in a NavigationStack/View which has always been the "you need to do this first" thing that everyone responds to on stack overflow.
Its broken as far as I can tell
Is this bug or problem?
This bug is fixed in iOS 16 beta 5.
Looks like the bug is back in iOS17. See the code below. When you start the app and show the fullScreenCover, it works as expected. However if you show the sheet, the keyboard button does not show anymore. And it will not show even in fullScreenCover until you restart the app.
struct ContentView: View {
@State var isSheetPresented = false
@State var isCoverPresented = false
var body: some View {
VStack {
Button("Show sheet (not working)") { isSheetPresented = true }
Button("Show cover (working)") { isCoverPresented = true }
}
.sheet(isPresented: $isSheetPresented) { SubView(isPresented: $isSheetPresented) }
.fullScreenCover(isPresented: $isCoverPresented) { SubView(isPresented: $isCoverPresented) }
}
}
struct SubView: View {
@State var text = ""
@Binding var isPresented: Bool
var body: some View {
NavigationView {
TextField("Text here...", text: $text)
.toolbar {
ToolbarItemGroup(placement: .topBarTrailing) {
Button("Dismiss") {
isPresented = false
}
}
ToolbarItemGroup(placement: .keyboard) {
Button("Keyboard button") {
print("keyboard button pressed")
}
}
}
}
}
}
hi,
i'm getting something similar in behavior related to toolbar items for the keyboard, although it's not exactly the same. (i am using Xcode 15 official release, not a beta or the RC.)
in my case, i have a view that can be shown either by navigating to it, or opening it in a sheet (wrapped inside a navigationStack).
- when the view is navigated to, the button i place on the keyboard (to dismiss the keyboard) works as expected.
- when the view is opened in a sheet (view is wrapped inside a navigationStack), the button does indeed appear, but it is disabled.
i'll try to put together a minimal example to file a feedback, but i'll be curious to see if there are more reports.
DMG
Same here with ToolbarItem(placement: .keyboard). It does not work anymore since iOS 17
Seems to work on device not on simulator (xcode 15.0.1) iOS 17.0.1
Xcode Version 15.2 (15C500b)
Here's the weird thing, it ONLY works if the sheet or parent view that opens the sheet is within a NavigationStack.
For example, this code fails to show the Keyboard button UNLESS you comment out one of those NavigationStacks:
struct ContentView: View {
@State var isPresented = false
var body: some View {
// NavigationStack { // Works
Button {
isPresented.toggle()
} label: {
Text("Button")
}
.sheet(isPresented: $isPresented) {
SubView()
}
// }
}
}
struct SubView: View {
@State var text = ""
var body: some View {
// NavigationStack { // Works
TextEditor(text: $text)
.toolbar {
ToolbarItemGroup(placement: .bottomBar) {
Button("Bottom Bar") {
}
}
ToolbarItemGroup(placement: .keyboard) {
NavigationStack {
Button("Keyboard") {
}
}
}
}
// }
}
}
FB13532834 Keyboard toolbar button does not display within sheet
It's back on Xcode 15.4