From acd18f3aa92aa16482b00e96e05eb3afaa53bbdc Mon Sep 17 00:00:00 2001 From: Stefan Ceriu Date: Tue, 6 Oct 2026 15:06:13 +0300 Subject: [PATCH] Fix location sharing double sheet presentation on the Mac Which would override each other and break the UI state --- .../View/LocationSharingScreen.swift | 22 ++++++++++++++++--- 1 file changed, 19 insertions(+), 3 deletions(-) diff --git a/ElementX/Sources/Screens/LocationSharing/View/LocationSharingScreen.swift b/ElementX/Sources/Screens/LocationSharing/View/LocationSharingScreen.swift index d1aedbe30..cb2b763f6 100644 --- a/ElementX/Sources/Screens/LocationSharing/View/LocationSharingScreen.swift +++ b/ElementX/Sources/Screens/LocationSharing/View/LocationSharingScreen.swift @@ -16,19 +16,19 @@ struct LocationSharingScreen: View { switch context.viewState.interactionMode { case .picker: mainContent - .sheet(isPresented: .constant(true)) { + .locationSheet { LocationPickerSheet(context: context) .alert(item: $context.alertInfo) } case .viewStatic: mainContent - .sheet(isPresented: .constant(true)) { + .locationSheet { StaticLocationSheet(context: context) .alert(item: $context.alertInfo) } case .viewLive: mainContent - .sheet(isPresented: .constant(true)) { + .locationSheet { LiveLocationSheet(context: context) .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(@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 struct LocationSharingScreen_Previews: PreviewProvider, TestablePreview {