Skip to content

Commit

Permalink
Rework ImageSize convenience APIs
Browse files Browse the repository at this point in the history
  • Loading branch information
kean committed Jan 14, 2025
1 parent a0abf4e commit 57714c7
Show file tree
Hide file tree
Showing 5 changed files with 9 additions and 8 deletions.
9 changes: 5 additions & 4 deletions Modules/Sources/AsyncImageKit/ImageRequest.swift
Original file line number Diff line number Diff line change
Expand Up @@ -66,16 +66,17 @@ public struct ImageSize: Hashable, Sendable {
self.height = Int(size.height)
}

/// Initializes `ImageSize` with the given size in **points** scaled for the given view.
/// A convenience initializer that creates `ImageSize` with the given size
/// in **points** scaled for the given view.
@MainActor
public init(scaling size: CGSize, in view: UIView) {
self.init(pixels: size.scaled(by: view.traitCollection.displayScale))
self.init(scaling: size, scale: view.traitCollection.displayScale)
}

/// Initializes `ImageSize` with the given size in **points** scaled for the
/// current trait collection display scale.
public init(scaling size: CGSize) {
self.init(pixels: size.scaled(by: UITraitCollection.current.displayScale))
public init(scaling size: CGSize, scale: CGFloat) {
self.init(pixels: size.scaled(by: max(1, scale)))
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -236,7 +236,7 @@ final class ExternalMediaPickerViewController: UIViewController, UICollectionVie
func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell {
let cell = collectionView.dequeueReusableCell(withReuseIdentifier: Self.cellReuseID, for: indexPath) as! ExternalMediaPickerCollectionCell
let item = dataSource.assets[indexPath.item]
cell.configure(imageURL: item.thumbnailURL, size: ImageSize(scaling: flowLayout.itemSize))
cell.configure(imageURL: item.thumbnailURL, size: ImageSize(scaling: flowLayout.itemSize, in: self.view))
return cell
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ class NoteBlockHeaderTableViewCell: NoteBlockTableViewCell {
if let gravatar = AvatarURL(url: url) {
authorAvatarImageView.downloadGravatar(gravatar, placeholder: .gravatarPlaceholderImage, animate: true)
} else {
authorAvatarImageView.wp.setImage(with: url, size: ImageSize(scaling: SiteIconViewModel.Size.regular.size))
authorAvatarImageView.wp.setImage(with: url, size: ImageSize(scaling: SiteIconViewModel.Size.regular.size, in: self))
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@ private final class ReaderCrossPostView: UIView {

avatarView.setPlaceholder(UIImage(named: "post-blavatar-placeholder"))
if let avatarURL = post.avatarURLForDisplay() {
let avatarSize = ImageSize(scaling: CGSize(width: avatarSize, height: avatarSize))
let avatarSize = ImageSize(scaling: CGSize(width: avatarSize, height: avatarSize), in: self)
avatarView.setImage(with: avatarURL, size: avatarSize)
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -360,7 +360,7 @@ private final class ReaderPostCellView: UIView {

private func setAvatar(with viewModel: ReaderPostCellViewModel) {
avatarView.setPlaceholder(UIImage(named: "post-blavatar-placeholder"))
let avatarSize = ImageSize(scaling: CGSize(width: ReaderPostCell.avatarSize, height: ReaderPostCell.avatarSize))
let avatarSize = ImageSize(scaling: CGSize(width: ReaderPostCell.avatarSize, height: ReaderPostCell.avatarSize), in: self)
if let avatarURL = viewModel.avatarURL {
avatarView.setImage(with: avatarURL, size: avatarSize)
} else {
Expand Down

0 comments on commit 57714c7

Please sign in to comment.