Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
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
19 changes: 11 additions & 8 deletions ImageSource/Core/ImageRequestOptions.swift
Original file line number Diff line number Diff line change
@@ -1,21 +1,24 @@
public struct ImageRequestOptions {

public var size: ImageSizeOption = .fullResolution
public var deliveryMode: ImageDeliveryMode = .best
public var size: ImageSizeOption
public var deliveryMode: ImageDeliveryMode
public var version: ImageRequestOptionsVersion
public let needsMetadata: Bool

/// Called on main thread when image download starts
public var onDownloadStart: ((ImageRequestId) -> ())?
/// Called on main thread when image download finishes
public var onDownloadFinish: ((ImageRequestId) -> ())?

public init() {
needsMetadata = false
}

public init(size: ImageSizeOption, deliveryMode: ImageDeliveryMode, needsMetadata: Bool = false) {

public init(
size: ImageSizeOption = .fullResolution,
deliveryMode: ImageDeliveryMode = .best,
version: ImageRequestOptionsVersion = .original,
needsMetadata: Bool = false
) {
self.size = size
self.deliveryMode = deliveryMode
self.version = version
self.needsMetadata = needsMetadata
}
}
13 changes: 13 additions & 0 deletions ImageSource/Core/ImageRequestOptionsVersion.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
/// Options for requesting an image asset with or without adjustments.
/// important: Can be applied to `PHAssetImageSource` only.
public enum ImageRequestOptionsVersion {

/// Request the most recent version of the image asset (the one that reflects all edits).
case current

/// Request a version of the image asset without adjustments.
case unadjusted

/// Request the original, highest-fidelity version of the image asset.
case original
}
11 changes: 10 additions & 1 deletion ImageSource/PHAsset/PHAssetImageSource.swift
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,7 @@ public final class PHAssetImageSource: ImageSource {
private func imageRequestParameters(from options: ImageRequestOptions)
-> (options: PHImageRequestOptions, size: CGSize, contentMode: PHImageContentMode)
{
let phOptions = PHImageRequestOptions()
let phOptions: PHImageRequestOptions = PHImageRequestOptions()
phOptions.isNetworkAccessAllowed = true

switch options.deliveryMode {
Expand All @@ -158,6 +158,15 @@ public final class PHAssetImageSource: ImageSource {
phOptions.deliveryMode = .highQualityFormat
phOptions.resizeMode = .exact
}

switch options.version {
case .current:
phOptions.version = .current
case .original:
phOptions.version = .original
case .unadjusted:
phOptions.version = .unadjusted
}

let size: CGSize
let contentMode: PHImageContentMode
Expand Down