Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Address remaining feedback for 25.7. #23977

Open
wants to merge 6 commits into
base: trunk
Choose a base branch
from
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
1 change: 1 addition & 0 deletions Modules/Sources/AsyncImageKit/ImagePrefetcher.swift
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,7 @@ public final class ImagePrefetcher {
value.task?.cancel()
}
queue.removeAll()
numberOfActiveTasks = 0
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I believe numberOfActiveTasks needs to be updated in stopPrefetching too.

}
}

Expand Down
33 changes: 19 additions & 14 deletions Modules/Sources/AsyncImageKit/ImageRequest.swift
Original file line number Diff line number Diff line change
Expand Up @@ -51,29 +51,34 @@ public struct ImageRequestOptions: Hashable, Sendable {

/// Image size in **pixels**.
public struct ImageSize: Hashable, Sendable {
public let width: CGFloat
public let height: CGFloat
/// Width in **pixels**.
public var width: Int
/// Height in **pixels**.
public var height: Int

public init(width: CGFloat, height: CGFloat) {
self.width = width
self.height = height
/// Initializes the struct with given size in **pixels**.
public init(width: Int, height: Int) {
self.width = Int(width)
self.height = Int(height)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Int(...) is not needed.

}

public init(_ size: CGSize) {
self.width = size.width
self.height = size.height
/// Initializes the struct with given size in **pixels**.
public init(pixels size: CGSize) {
self.width = Int(size.width)
self.height = Int(size.height)
}

/// Initializes `ImageSize` with the given size 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(size.scaled(by: view.traitCollection.displayScale))
self.init(scaling: size, scale: view.traitCollection.displayScale)
}

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

Expand Down
1 change: 1 addition & 0 deletions Modules/Sources/AsyncImageKit/Views/AsyncImageView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ public final class AsyncImageView: UIView {
/// By default, `background`.
public var loadingStyle = LoadingStyle.background

// TODO: remove when WPRichTextImage is removed
public var passTouchesToSuperview = false

public init() {}
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
Loading