Fix location sharing double sheet presentation on the Mac

Which would override each other and break the UI state
This commit is contained in:
Stefan Ceriu
2026-10-06 15:06:13 +03:00
parent 4640f9cec0
commit acd18f3aa9
@@ -16,19 +16,19 @@ struct LocationSharingScreen: View {
switch context.viewState.interactionMode { switch context.viewState.interactionMode {
case .picker: case .picker:
mainContent mainContent
.sheet(isPresented: .constant(true)) { .locationSheet {
LocationPickerSheet(context: context) LocationPickerSheet(context: context)
.alert(item: $context.alertInfo) .alert(item: $context.alertInfo)
} }
case .viewStatic: case .viewStatic:
mainContent mainContent
.sheet(isPresented: .constant(true)) { .locationSheet {
StaticLocationSheet(context: context) StaticLocationSheet(context: context)
.alert(item: $context.alertInfo) .alert(item: $context.alertInfo)
} }
case .viewLive: case .viewLive:
mainContent mainContent
.sheet(isPresented: .constant(true)) { .locationSheet {
LiveLocationSheet(context: context) LiveLocationSheet(context: context)
.alert(item: $context.alertInfo) .alert(item: $context.alertInfo)
} }
@@ -122,6 +122,22 @@ struct LocationSharingScreen: View {
} }
} }
private extension View {
/// The Mac hides a sheet's parent sheet while it's presented, taking the close button with it.
@ViewBuilder
func locationSheet<Content: View>(@ViewBuilder content: @escaping () -> Content) -> some View {
if ProcessInfo.processInfo.isiOSAppOnMac {
safeAreaInset(edge: .bottom, spacing: 0) {
content()
.fixedSize(horizontal: false, vertical: true)
.background(.compound.bgCanvasDefault)
}
} else {
sheet(isPresented: .constant(true), content: content)
}
}
}
// MARK: - Previews // MARK: - Previews
struct LocationSharingScreen_Previews: PreviewProvider, TestablePreview { struct LocationSharingScreen_Previews: PreviewProvider, TestablePreview {