summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--Sora/Other/AsyncImageWithPreview.swift23
1 files changed, 17 insertions, 6 deletions
diff --git a/Sora/Other/AsyncImageWithPreview.swift b/Sora/Other/AsyncImageWithPreview.swift
index 6c47fb9..488e66e 100644
--- a/Sora/Other/AsyncImageWithPreview.swift
+++ b/Sora/Other/AsyncImageWithPreview.swift
@@ -12,6 +12,19 @@ struct AsyncImageWithPreview<Placeholder: View>: View {
@State private var currentOffset: CGSize = .zero
@State private var finalOffset: CGSize = .zero
+ var keyWindow: UIWindow? {
+ guard
+ let window = UIApplication.shared.connectedScenes
+ .compactMap({ $0 as? UIWindowScene })
+ .flatMap(\.windows)
+ .first(where: \.isKeyWindow)
+ else {
+ return nil
+ }
+
+ return window
+ }
+
var body: some View {
AsyncImage(url: url) { image in
ZoomableImageView(image: image)
@@ -37,12 +50,10 @@ struct AsyncImageWithPreview<Placeholder: View>: View {
#if os(iOS)
if settings.enableShareShortcut {
Button {
- let activityViewController = UIActivityViewController(
- activityItems: [url ?? URL(string: "")!], applicationActivities: nil
- )
-
- UIApplication.shared.windows.first?.rootViewController?.present(
- activityViewController, animated: true
+ keyWindow?.rootViewController?.present(
+ UIActivityViewController(
+ activityItems: [url ?? URL(string: "")!], applicationActivities: nil
+ ), animated: true
)
} label: {
Label("Share Image", systemImage: "square.and.arrow.up")