Skip to content

Commit

Permalink
Remove AlamofireImage (#23927)
Browse files Browse the repository at this point in the history
  • Loading branch information
kean authored Dec 24, 2024
2 parents f09a0cd + 53f578d commit e039957
Show file tree
Hide file tree
Showing 5 changed files with 7 additions and 70 deletions.
2 changes: 0 additions & 2 deletions Modules/Package.swift
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ let package = Package(
dependencies: [
.package(url: "https://github.com/airbnb/lottie-ios", from: "4.4.0"),
.package(url: "https://github.com/Alamofire/Alamofire", from: "5.9.1"),
.package(url: "https://github.com/Alamofire/AlamofireImage", from: "4.3.0"),
.package(url: "https://github.com/AliSoftware/OHHTTPStubs", from: "9.1.0"),
.package(url: "https://github.com/Automattic/Automattic-Tracks-iOS", from: "3.4.2"),
.package(url: "https://github.com/Automattic/AutomatticAbout-swift", from: "1.1.4"),
Expand Down Expand Up @@ -146,7 +145,6 @@ enum XcodeSupport {
"WordPressMedia",
"WordPressUI",
.product(name: "Alamofire", package: "Alamofire"),
.product(name: "AlamofireImage", package: "AlamofireImage"),
.product(name: "AutomatticAbout", package: "AutomatticAbout-swift"),
.product(name: "AutomatticTracks", package: "Automattic-Tracks-iOS"),
.product(name: "CocoaLumberjack", package: "CocoaLumberjack"),
Expand Down
11 changes: 1 addition & 10 deletions WordPress.xcworkspace/xcshareddata/swiftpm/Package.resolved
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"originHash" : "e67326cf4e0b967f85976c160b6e3742a401276eabf3e18b25fce8bb219e1350",
"originHash" : "2325eaeb036deffbb1d475c9c1b62fef474fe61fdbea5d4335dd314f4bd5cab6",
"pins" : [
{
"identity" : "alamofire",
Expand All @@ -10,15 +10,6 @@
"version" : "5.9.1"
}
},
{
"identity" : "alamofireimage",
"kind" : "remoteSourceControl",
"location" : "https://github.com/Alamofire/AlamofireImage",
"state" : {
"revision" : "1eaf3b6c6882bed10f6e7b119665599dd2329aa1",
"version" : "4.3.0"
}
},
{
"identity" : "automattic-tracks-ios",
"kind" : "remoteSourceControl",
Expand Down
48 changes: 0 additions & 48 deletions WordPress/Classes/Utility/Media/MemoryCache+Extensions.swift
Original file line number Diff line number Diff line change
@@ -1,18 +1,12 @@
import UIKit
import WordPressMedia
import AlamofireImage
import WordPressUI

extension MemoryCache {
/// Registers the cache with all the image loading systems used by the app.
func register() {
// WordPressUI
WordPressUI.ImageCache.shared = WordpressUICacheAdapter(cache: .shared)

// AlamofireImage
UIImageView.af.sharedImageDownloader = AlamofireImage.ImageDownloader(
imageCache: AlamofireImageCacheAdapter(cache: .shared)
)
}
}

Expand All @@ -27,45 +21,3 @@ private struct WordpressUICacheAdapter: WordPressUI.ImageCaching {
cache.getImage(forKey: key)
}
}

private struct AlamofireImageCacheAdapter: AlamofireImage.ImageRequestCache {
let cache: MemoryCache

func image(for request: URLRequest, withIdentifier identifier: String?) -> AlamofireImage.Image? {
image(withIdentifier: cacheKey(for: request, identifier: identifier))
}

func add(_ image: AlamofireImage.Image, for request: URLRequest, withIdentifier identifier: String?) {
add(image, withIdentifier: cacheKey(for: request, identifier: identifier))
}

func removeImage(for request: URLRequest, withIdentifier identifier: String?) -> Bool {
removeImage(withIdentifier: cacheKey(for: request, identifier: identifier))
}

func image(withIdentifier identifier: String) -> AlamofireImage.Image? {
cache.getImage(forKey: identifier)
}

func add(_ image: AlamofireImage.Image, withIdentifier identifier: String) {
cache.setImage(image, forKey: identifier)
}

func removeImage(withIdentifier identifier: String) -> Bool {
cache.removeImage(forKey: identifier)
return true
}

func removeAllImages() -> Bool {
// Do nothing (the app decides when to remove images)
return true
}

private func cacheKey(for request: URLRequest, identifier: String?) -> String {
var key = request.url?.absoluteString ?? ""
if let identifier {
key += "-\(identifier)"
}
return key
}
}
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import UIKit

class AnnouncementCell: AnnouncementTableViewCell {

Expand Down Expand Up @@ -59,7 +60,7 @@ class AnnouncementCell: AnnouncementTableViewCell {
}

else if let url = URL(string: feature.iconUrl) {
announcementImageView.af.setImage(withURL: url)
announcementImageView.wp.setImage(with: url)
}
headingLabel.text = feature.title
subHeadingLabel.text = feature.subtitle
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,20 +65,15 @@ class DashboardCustomAnnouncementCell: AnnouncementTableViewCell {
func configure(feature: WordPressKit.Feature) {

if let url = URL(string: feature.iconUrl) {
announcementImageView.af.setImage(withURL: url, completion: { [weak self] response in

guard let self,
let width = response.value?.size.width,
let height = response.value?.size.height else {
announcementImageView.wp.setImage(with: url) { [weak self] result in
guard let self, case .success(let image) = result else {
return
}

let aspectRatio = width / height

let aspectRatio = image.size.width / image.size.height
NSLayoutConstraint.activate([
self.announcementImageView.widthAnchor.constraint(equalTo: self.announcementImageView.heightAnchor, multiplier: aspectRatio)
])
})
}
}
headingLabel.text = feature.subtitle
}
Expand Down

0 comments on commit e039957

Please sign in to comment.