When a Picker is showing, if you tap on a button outside the Picker view that shows a Sheet, the sheet fails to show and subsequently showing any sheet will fail until you restart the app.
This only happens when the button that shows the sheet is too close to the bottom of the screen. If you provide some space between the bottom of the button and the screen (i.e. 50 Points), there is no longer an issue.
I reproduced this with Xcode 14.2 on an iPhone Xs (iOS 16.1.1) and the iPhone 14 Sim (iOS 16.2). It does not occur when testing with Playgrounds.
The error:
[Presentation] Attempt to present <TtGC7SwiftUI29PresentationHostingControllerVS_7AnyView: 0x7fae7585de00> on <TtGC7SwiftUI19UIHostingControllerGVS_15ModifiedContentVS_7AnyViewVS_12RootModifier_: 0x7fae76011800> (from <TtGC7SwiftUI19UIHostingControllerGVS_15ModifiedContentVS_7AnyViewVS_12RootModifier_: 0x7fae76011800>) which is already presenting <_UIDatePickerContainerViewController: 0x7fae756b0f00>.
struct ContentView: View {
@State private var showSheet = false
@State var selectedDate: Date = Date()
var body: some View {
VStack {
DatePicker(selection: $selectedDate) {
Text("Select Date")
}
Spacer()
HStack {
Button {
showSheet = true
} label: {
Text("Show Sheet Working")
.background(Color.green)
}
.offset(.init(width: 10.0, height: -45.0))
Button {
showSheet = true
} label: {
Text("Show Sheet Broken")
.background(Color.red)
}
.offset(.init(width: 10.0, height: -35.0))
}
}
.sheet(isPresented: $showSheet) {
Text("Hello World")
}
}
}
To reproduce, run the above code and tap the Date picker at the top. Tapping the green button which has more space from the bottom does not pose the issue. Tapping the red button causes the bug.