Created
July 25, 2024 00:45
-
-
Save zachwaugh/820c7316fa54df071f28ce01c9c0b422 to your computer and use it in GitHub Desktop.
Sample app to reproduce a ShareLink bug when used in a sheet with a confirmationDialog
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import SwiftUI | |
// Sample app to reproduce ShareLink bug from a sheet | |
// 1. Run app, tap "Present Modal Sheet" | |
// 2. Try to Share from the sheet | |
// 3. It won't present and you'll see an error in the console: | |
// Attempt to present <UIActivityViewController: 0x102820000> on <_TtGC7SwiftUI19UIHostingControllerGVS_15ModifiedContentVS_7AnyViewVS_12RootModifier__: 0x102020e00> (from <_TtGC7SwiftUI32NavigationStackHostingControllerVS_7AnyView_: 0x103829a00>) which is already presenting <_TtGC7SwiftUI29PresentationHostingControllerVS_7AnyView_: 0x10202a800>. | |
// 4. Comment out the .confirmationDialog line and it works | |
// 5. Move .confirmationDialog before .sheet and it works | |
@main | |
struct TestApp: App { | |
var body: some Scene { | |
WindowGroup { | |
ContentView() | |
} | |
} | |
} | |
struct ContentView: View { | |
@State private var isSheetPresented = false | |
@State private var isConfirmationDialogPresented = false | |
var body: some View { | |
NavigationStack { | |
VStack { | |
Spacer() | |
Button { | |
isSheetPresented.toggle() | |
} label: { | |
Text("Present Modal Sheet") | |
} | |
.buttonStyle(.borderedProminent) | |
Spacer() | |
} | |
.padding() | |
.sheet(isPresented: $isSheetPresented) { | |
NavigationStack { | |
VStack { | |
Spacer() | |
ShareLink(item: "Test - Share from Sheet") { | |
Text("Share from Sheet") | |
} | |
Spacer() | |
} | |
.navigationTitle("Sheet") | |
.navigationBarTitleDisplayMode(.inline) | |
} | |
.presentationDetents([.medium, .large]) | |
} | |
// *** This breaks sharing from a modal *** | |
.confirmationDialog("Test", isPresented: $isConfirmationDialogPresented, actions: {}) | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment