When I run the following code, once I open and close the sheet, the toolbar buttons become unusable. When there is only one button, there is no problem, but when there are two buttons, this phenomenon occurs. Is there a workaround?
The environment is Xcode: 12.5, iOS: 14.5.
import SwiftUI
struct ContentView: View {
@State private var showingSheet = false
var body: some View {
NavigationView {
Text("1st View")
.toolbar {
ToolbarItem(placement: .navigationBarTrailing) {
HStack {
Button("Button1") {
showingSheet = true
}
Button("Button2") {
showingSheet = true
}
}
}
}
.sheet(isPresented: $showingSheet) {
Sheet()
}
}
}
}
struct Sheet: View {
@Environment(\.presentationMode) var presentationMode
var body: some View {
Button("close sheet") {
presentationMode.wrappedValue.dismiss()
}
}
}
your code as it is works well for me on macos 11.4, xcode 12.5, target ios 14.5 and macCatalyst 11.3.
Thank you for the information. I tried it on a real machine and it works as you said. It seems to be a problem with the simulator.