Skip to content
This repository has been archived by the owner on Dec 15, 2024. It is now read-only.

GIF Animation Implementation #179

Open
wants to merge 27 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
27 commits
Select commit Hold shift + click to select a range
ba86cb5
gif support
0xfeedface1993 Apr 21, 2024
7ec9f36
gif init
0xfeedface1993 Apr 21, 2024
196e320
update git wapper method
0xfeedface1993 Apr 21, 2024
8546bfd
wrapper image
0xfeedface1993 Apr 21, 2024
d923741
Coordinator image loader
0xfeedface1993 Apr 21, 2024
5320985
fix async call
0xfeedface1993 Apr 21, 2024
68f66d1
mac support
0xfeedface1993 Apr 21, 2024
ab30ecb
fix nsimage generate state
0xfeedface1993 Apr 21, 2024
5011be8
fix @available statement
0xfeedface1993 Apr 21, 2024
f87a5f2
fix finalizeDestination:3546: *** ERROR: image destination does not h…
0xfeedface1993 Apr 21, 2024
1024a3f
more efficency load gif on macOS
0xfeedface1993 Apr 21, 2024
73ed82d
try fix memeory problem
0xfeedface1993 Apr 23, 2024
ed308c9
fix imageview not visible
0xfeedface1993 Apr 23, 2024
c1d79c2
remove invalid binding state
0xfeedface1993 Apr 23, 2024
441fe6e
fix missing update gif data method
0xfeedface1993 Apr 23, 2024
8333470
GIFImage impelment
0xfeedface1993 Apr 25, 2024
1d5ab58
upgrade iOS version
0xfeedface1993 Apr 25, 2024
2587c14
fix SPM dependencies
0xfeedface1993 Apr 25, 2024
c71542c
fix gif image size not display in correct aspect ratio
0xfeedface1993 Apr 26, 2024
43ae654
add aspectResizeble(ratio:contentMode:) api, it will behavior like Im…
0xfeedface1993 Apr 26, 2024
9f3e9b9
update README
0xfeedface1993 Apr 26, 2024
3a6e8a0
remove unowned self reference
0xfeedface1993 May 27, 2024
f0f5ab0
fix URLImageOption read in init life cycle
0xfeedface1993 Jul 8, 2024
ba69f93
baseline image gallary function
0xfeedface1993 Jul 27, 2024
3cc0a76
swift 6 error fixed
0xfeedface1993 Sep 24, 2024
7ec4a33
swift 6 error
0xfeedface1993 Sep 24, 2024
9b55096
fix swift concurency bug
0xfeedface1993 Oct 1, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions Dependencies/Sources/DownloadManager/Download/Download.swift
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,13 @@ import Foundation
/**
The `Download` object describes a single file download.
*/
public struct Download {
public struct Download: Sendable {

public var url: URL

public var id: UUID

public enum Destination : Codable, Hashable {
public enum Destination : Codable, Hashable, Sendable {

/// Download to a shared buffer in memory
case inMemory
Expand Down Expand Up @@ -70,7 +70,7 @@ public struct Download {

public var destination: Destination

public struct DownloadPolicy : OptionSet, Codable, Hashable {
public struct DownloadPolicy : OptionSet, Codable, Hashable, Sendable {

public let rawValue: Int

Expand All @@ -84,7 +84,7 @@ public struct Download {

public var downloadPolicy: DownloadPolicy

public struct URLRequestConfiguration : Hashable, Codable {
public struct URLRequestConfiguration : Hashable, Codable, Sendable {

public var allHTTPHeaderFields: [String : String]?

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,82 +21,75 @@ public struct DownloadPublisher: Publisher {
DownloadPublisher.Failure == S.Failure,
DownloadPublisher.Output == S.Input
{
let subscription = DownloadSubscription(subscriber: subscriber, download: download, manager: manager)
let subscription = DownloadSubscription(subscriber: subscriber, download: download, coordinator: coordinator)
subscriber.receive(subscription: subscription)
}

init(download: Download, manager: DownloadManager) {
init(download: Download, coordinator: URLSessionCoordinator) {
self.download = download
self.manager = manager
self.coordinator = coordinator
}

private let manager: DownloadManager
private let coordinator: URLSessionCoordinator
}


@available(macOS 11.0, iOS 14.0, tvOS 14.0, watchOS 7.0, *)
final class DownloadSubscription<SubscriberType: Subscriber>: Subscription
where SubscriberType.Input == DownloadInfo,
SubscriberType.Failure == DownloadError
final class DownloadSubscription<SubscriberType: Subscriber>: Subscription where SubscriberType.Input == DownloadInfo, SubscriberType.Failure == DownloadError
{
private var subscriber: SubscriberType?

private let download: Download

private unowned let manager: DownloadManager
private unowned let coordinator: URLSessionCoordinator

init(subscriber: SubscriberType, download: Download, manager: DownloadManager) {
init(subscriber: SubscriberType, download: Download, coordinator: URLSessionCoordinator) {
self.subscriber = subscriber
self.download = download
self.manager = manager
self.coordinator = coordinator
}

func request(_ demand: Subscribers.Demand) {
guard demand > 0 else { return }

log_debug(self, #function, "download.id = \(download.id), download.url = \(self.download.url)", detail: log_detailed)
nonisolated(unsafe) let subscriber = subscriber
let download = download
let type = Self.self

manager.coordinator.startDownload(download,
coordinator.startDownload(download,
receiveResponse: { _ in
},
receiveData: { _, _ in
},
reportProgress: { [weak self] _, progress in
guard let self = self else {
return
}

let _ = self.subscriber?.receive(.progress(progress))
reportProgress: { _, progress in
let _ = subscriber?.receive(.progress(progress))
},
completion: { [weak self] _, result in
guard let self = self else {
return
}

completion: { _, result in
switch result {
case .success(let downloadResult):
switch downloadResult {
case .data(let data):
log_debug(self, #function, "download.id = \(self.download.id), download.url = \(self.download.url), downloaded \(data.count) bytes", detail: log_detailed)
log_debug(type, #function, "download.id = \(download.id), download.url = \(download.url), downloaded \(data.count) bytes", detail: log_detailed)
case .file(let path):
log_debug(self, #function, "download.id = \(self.download.id), download.url = \(self.download.url), downloaded file to \(path)", detail: log_detailed)
log_debug(type, #function, "download.id = \(download.id), download.url = \(download.url), downloaded file to \(path)", detail: log_detailed)
}

let _ = self.subscriber?.receive(.completion(downloadResult))
self.subscriber?.receive(completion: .finished)
let _ = subscriber?.receive(.completion(downloadResult))
subscriber?.receive(completion: .finished)

case .failure(let error):
log_debug(self, #function, "download.id = \(self.download.id), download.url = \(self.download.url), downloaded failed \(error)", detail: log_detailed)
self.subscriber?.receive(completion: .failure(error))
log_debug(type, #function, "download.id = \(download.id), download.url = \(download.url), downloaded failed \(error)", detail: log_detailed)
subscriber?.receive(completion: .failure(error))
}

self.manager.reset(download: self.download)
// self.manager.reset(download: self.download)
})
}

func cancel() {
log_debug(self, #function, "download.id = \(download.id), download.url = \(self.download.url)", detail: log_detailed)
manager.coordinator.cancelDownload(download)
manager.reset(download: download)
coordinator.cancelDownload(download)
// manager.reset(download: download)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,9 @@ import Foundation


/// `DownloadTask` is a wrapper around `URLSessionTask` that accumulates received data in a memory buffer.
final class DownloadTask {
final class DownloadTask: @unchecked Sendable {

final class Observer {
final class Observer: @unchecked Sendable {

private var receiveResponse: DownloadReceiveResponse?

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,15 @@
import Foundation


public enum DownloadResult {
public enum DownloadResult: Sendable {

case data(_ data: Data)

case file(_ path: String)
}


public enum DownloadInfo {
public enum DownloadInfo: Sendable {

case progress(_ progress: Float?)

Expand All @@ -28,7 +28,7 @@ extension DownloadResult : Hashable {}

public typealias DownloadError = Error

public typealias DownloadReceiveResponse = (_ download: Download) -> Void
public typealias DownloadReceiveData = (_ download: Download, _ data: Data) -> Void
public typealias DownloadReportProgress = (_ download: Download, _ progress: Float?) -> Void
public typealias DownloadCompletion = (_ download: Download, _ result: Result<DownloadResult, DownloadError>) -> Void
public typealias DownloadReceiveResponse = @Sendable (_ download: Download) -> Void
public typealias DownloadReceiveData = @Sendable (_ download: Download, _ data: Data) -> Void
public typealias DownloadReportProgress = @Sendable (_ download: Download, _ progress: Float?) -> Void
public typealias DownloadCompletion = @Sendable (_ download: Download, _ result: Result<DownloadResult, DownloadError>) -> Void
Loading