From c73e15fdb2ae9e29a66bc75e92ac8e56c4adaedf Mon Sep 17 00:00:00 2001 From: Fuwn Date: Sat, 22 Feb 2025 06:49:57 -0800 Subject: feat: Development commit --- Sora/Other/AsyncImageWithPreview.swift | 23 +++++++++++++++++------ 1 file 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: 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: 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") -- cgit v1.2.3