Skip to content

Commit

Permalink
Remove ImageLoader usages from Blaze
Browse files Browse the repository at this point in the history
  • Loading branch information
kean committed Dec 12, 2024
1 parent 9e972b6 commit 5bc3c60
Show file tree
Hide file tree
Showing 5 changed files with 18 additions and 32 deletions.
1 change: 1 addition & 0 deletions WordPress/Classes/Utility/Media/AsyncImageView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ final class AsyncImageView: UIView {
}
}

/// - parameter size: Target image size in pixels.
func setImage(
with imageURL: URL,
host: MediaHost? = nil,
Expand Down
2 changes: 1 addition & 1 deletion WordPress/Classes/Utility/Media/ImageRequest.swift
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ final class ImageRequest {
}

struct ImageRequestOptions {
/// Resize the thumbnail to the given size. By default, `nil`.
/// Resize the thumbnail to the given size (in pixels). By default, `nil`.
var size: CGSize?

/// If enabled, uses ``MemoryCache`` for caching decompressed images.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,10 +67,9 @@ final class BlazeCampaignTableViewCell: UITableViewCell, Reusable {
return stackView
}()

private lazy var featuredImageView: CachedAnimatedImageView = {
let imageView = CachedAnimatedImageView()
private lazy var featuredImageView: AsyncImageView = {
let imageView = AsyncImageView()
imageView.translatesAutoresizingMaskIntoConstraints = false
imageView.contentMode = .scaleAspectFill
imageView.clipsToBounds = true
imageView.layer.cornerRadius = Metrics.featuredImageCornerRadius
return imageView
Expand All @@ -85,12 +84,6 @@ final class BlazeCampaignTableViewCell: UITableViewCell, Reusable {
return imageView
}()

// MARK: - Properties

private lazy var imageLoader: ImageLoader = {
return ImageLoader(imageView: featuredImageView, gifStrategy: .mediumGIFs)
}()

// MARK: - Initializers

override init(style: UITableViewCell.CellStyle, reuseIdentifier: String?) {
Expand All @@ -110,15 +103,15 @@ final class BlazeCampaignTableViewCell: UITableViewCell, Reusable {

titleLabel.text = viewModel.title

imageLoader.prepareForReuse()
featuredImageView.prepareForReuse()
featuredImageView.isHidden = viewModel.imageURL == nil
if let imageURL = viewModel.imageURL {
let host = MediaHost(with: blog, failure: { error in
WordPressAppDelegate.crashLogging?.logError(error)
})

let preferredSize = CGSize(width: Metrics.featuredImageSize, height: Metrics.featuredImageSize)
imageLoader.loadImage(with: imageURL, from: host, preferredSize: preferredSize)
.scaled(by: UITraitCollection.current.displayScale)
featuredImageView.setImage(with: imageURL, host: host, size: preferredSize)
}

statsStackView.arrangedSubviews.forEach { $0.removeFromSuperview() }
Expand All @@ -131,11 +124,6 @@ final class BlazeCampaignTableViewCell: UITableViewCell, Reusable {

private func commonInit() {
setupViews()
applyStyle()
}

private func applyStyle() {
backgroundColor = .systemGroupedBackground
}

private func setupViews() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,8 @@ final class BlazePostPreviewView: UIView {
return label
}()

private lazy var featuredImageView: CachedAnimatedImageView = {
let imageView = CachedAnimatedImageView()
private lazy var featuredImageView: AsyncImageView = {
let imageView = AsyncImageView()
imageView.translatesAutoresizingMaskIntoConstraints = false

NSLayoutConstraint.activate([
Expand All @@ -66,10 +66,6 @@ final class BlazePostPreviewView: UIView {

private let post: AbstractPost

private lazy var imageLoader: ImageLoader = {
return ImageLoader(imageView: featuredImageView, gifStrategy: .mediumGIFs)
}()

// MARK: - Initializers

init(post: AbstractPost) {
Expand All @@ -95,16 +91,17 @@ final class BlazePostPreviewView: UIView {
}

private func setupFeaturedImage() {
featuredImageView.prepareForReuse()

if let url = post.featuredImageURL {
featuredImageView.isHidden = false

let host = MediaHost(with: post, failure: { error in
// We'll log the error, so we know it's there, but we won't halt execution.
WordPressAppDelegate.crashLogging?.logError(error)
})

let preferredSize = CGSize(width: featuredImageView.frame.width, height: featuredImageView.frame.height)
imageLoader.loadImage(with: url, from: host, preferredSize: preferredSize)
.scaled(by: UITraitCollection.current.displayScale)
featuredImageView.setImage(with: url, host: host, size: preferredSize)

} else {
featuredImageView.isHidden = true
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,16 +5,14 @@ import WordPressKit
final class DashboardBlazeCampaignView: UIView {
private let statusView = BlazeCampaignStatusView()
private let titleLabel = UILabel()
private let imageView = CachedAnimatedImageView()
private let imageView = AsyncImageView()

private lazy var statsView: UIStackView = {
let stackView = UIStackView()
stackView.distribution = .fillEqually
return stackView
}()

private lazy var imageLoader = ImageLoader(imageView: imageView)

override init(frame: CGRect) {
super.init(frame: frame)

Expand Down Expand Up @@ -59,13 +57,15 @@ final class DashboardBlazeCampaignView: UIView {

titleLabel.text = viewModel.title

imageLoader.prepareForReuse()
imageView.prepareForReuse()
imageView.isHidden = viewModel.imageURL == nil
if let imageURL = viewModel.imageURL {
let host = MediaHost(with: blog, failure: { error in
WordPressAppDelegate.crashLogging?.logError(error)
})
imageLoader.loadImage(with: imageURL, from: host, preferredSize: Constants.imageSize)
let targetSize = Constants.imageSize
.scaled(by: UITraitCollection.current.displayScale)
imageView.setImage(with: imageURL, host: host, size: targetSize)
}

statsView.isHidden = !viewModel.isShowingStats
Expand Down

0 comments on commit 5bc3c60

Please sign in to comment.