diff options
| author | Fuwn <[email protected]> | 2025-02-22 07:07:57 -0800 |
|---|---|---|
| committer | Fuwn <[email protected]> | 2025-02-22 07:07:57 -0800 |
| commit | cafece91bae45194d64f4932bb04be018b82d21b (patch) | |
| tree | 02d727a13fe530550e3b29b28b7ee9980262eef2 /Sora/Other | |
| parent | feat: Development commit (diff) | |
| download | sora-testing-cafece91bae45194d64f4932bb04be018b82d21b.tar.xz sora-testing-cafece91bae45194d64f4932bb04be018b82d21b.zip | |
feat: Development commit
Diffstat (limited to 'Sora/Other')
| -rw-r--r-- | Sora/Other/AsyncImageWithPreview.swift | 106 | ||||
| -rw-r--r-- | Sora/Other/PostLoadingState.swift | 5 |
2 files changed, 0 insertions, 111 deletions
diff --git a/Sora/Other/AsyncImageWithPreview.swift b/Sora/Other/AsyncImageWithPreview.swift deleted file mode 100644 index 56af307..0000000 --- a/Sora/Other/AsyncImageWithPreview.swift +++ /dev/null @@ -1,106 +0,0 @@ -import SwiftUI - -struct AsyncImageWithPreview<Placeholder: View>: View { - @EnvironmentObject var settings: Settings - var url: URL? - @Binding var loadingState: PostLoadingState - var finalLoadingState: PostLoadingState - var postURL: URL? - let placeholder: () -> Placeholder - @State private var currentScale: CGFloat = 1.0 - @State private var finalScale: CGFloat = 1.0 - @State private var currentOffset: CGSize = .zero - @State private var finalOffset: CGSize = .zero - - #if os(iOS) - var keyWindow: UIWindow? { - guard - let window = UIApplication.shared.connectedScenes - .compactMap({ $0 as? UIWindowScene }) - .flatMap(\.windows) - .first(where: \.isKeyWindow) - else { - return nil - } - - return window - } - #endif - - var body: some View { - AsyncImage(url: url) { image in - ZoomableImageView(image: image) - .onAppear { - loadingState = finalLoadingState - } - .contextMenu { - #if os(iOS) - Button { - guard let url else { return } - - URLSession.shared.dataTask(with: url) { data, _, _ in - guard let data, let uiImage = UIImage(data: data) else { return } - - UIImageWriteToSavedPhotosAlbum(uiImage, nil, nil, nil) - } - .resume() - } label: { - Label("Save Image", systemImage: "square.and.arrow.down") - } - #endif - - #if os(iOS) - if settings.enableShareShortcut { - Button { - keyWindow?.rootViewController?.present( - UIActivityViewController( - activityItems: [url ?? URL(string: "")!], applicationActivities: nil - ), animated: true - ) - } label: { - Label("Share Image", systemImage: "square.and.arrow.up") - } - } - #endif - - if let url = postURL { - Button { - #if os(iOS) - UIApplication.shared.open(url) - #else - NSWorkspace.shared.open(url) - #endif - } label: { - Label("Open in Safari", systemImage: "safari") - } - } - } - } placeholder: { - placeholder() - .onAppear { - loadingState = .loadingPreview - } - } - } - - init( - url: URL?, - loadingStage: Binding<PostLoadingState>, - finalLoadingState: PostLoadingState = .loadingFile, - postURL: URL? = nil, - @ViewBuilder placeholder: @escaping () -> Placeholder = { - GeometryReader { geometry in - ProgressView() - .frame(width: geometry.size.width, height: geometry.size.height) - .position(x: geometry.size.width / 2, y: geometry.size.height / 2) - .padding() - } - } - ) { - self.url = url - _loadingState = loadingStage - self.finalLoadingState = finalLoadingState - self.postURL = postURL - self.placeholder = placeholder - } -} diff --git a/Sora/Other/PostLoadingState.swift b/Sora/Other/PostLoadingState.swift deleted file mode 100644 index 7af533f..0000000 --- a/Sora/Other/PostLoadingState.swift +++ /dev/null @@ -1,5 +0,0 @@ -enum PostLoadingState { - case loaded - case loadingFile - case loadingPreview -} |