diff options
| author | Fuwn <[email protected]> | 2025-02-22 06:49:57 -0800 |
|---|---|---|
| committer | Fuwn <[email protected]> | 2025-02-22 06:49:57 -0800 |
| commit | c73e15fdb2ae9e29a66bc75e92ac8e56c4adaedf (patch) | |
| tree | 208645c0c78fe74e9098e5c0c47e5be779b26002 | |
| parent | feat: Development commit (diff) | |
| download | sora-testing-c73e15fdb2ae9e29a66bc75e92ac8e56c4adaedf.tar.xz sora-testing-c73e15fdb2ae9e29a66bc75e92ac8e56c4adaedf.zip | |
feat: Development commit
| -rw-r--r-- | Sora/Other/AsyncImageWithPreview.swift | 23 |
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") |