Skip to content

Commit

Permalink
Added image caching for icons
Browse files Browse the repository at this point in the history
  • Loading branch information
joshdholtz committed Jan 14, 2025
1 parent 30ba5cd commit ee492f3
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 2 deletions.
33 changes: 32 additions & 1 deletion Sources/Paywalls/Components/PaywallV2CacheWarming.swift
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,13 @@ extension PaywallComponentsData.PaywallComponentsConfig {
switch component {
case .text:
()
case .icon(let icon):
guard let baseUrl = URL(string: icon.baseUrl) else {
break
}

urls += icon.formats.imageUrls(base: baseUrl)
urls += icon.overrides?.imageUrls(base: baseUrl) ?? []
case .image(let image):
urls += [
image.source.light.heicLowRes,
Expand Down Expand Up @@ -96,7 +103,31 @@ extension PaywallComponentsData.PaywallComponentsConfig {

}

extension PaywallComponent.ThemeImageUrls {
extension PaywallComponent.IconComponent.Formats {

func imageUrls(base: URL) -> [URL] {
return [
base.appendingPathComponent(heic)
]
}

}

extension PaywallComponent.ComponentOverrides where T == PaywallComponent.PartialIconComponent {

func imageUrls(base: URL) -> [URL] {
return [
self.introOffer?.formats?.imageUrls(base: base) ?? [],
self.states?.selected?.formats?.imageUrls(base: base) ?? [],
self.conditions?.compact?.formats?.imageUrls(base: base) ?? [],
self.conditions?.medium?.formats?.imageUrls(base: base) ?? [],
self.conditions?.expanded?.formats?.imageUrls(base: base) ?? []
].flatMap { $0 }
}

}

private extension PaywallComponent.ThemeImageUrls {

var imageUrls: [URL] {
return [
Expand Down
2 changes: 1 addition & 1 deletion Sources/Paywalls/PaywallCacheWarming.swift
Original file line number Diff line number Diff line change
Expand Up @@ -178,7 +178,7 @@ private extension Offerings {
#if PAYWALL_COMPONENTS

private var allImagesInPaywallsV2: Set<URL> {
// Attempting to warm up all offerings for Paywalls V2.
// Attempting to warm up all low res images for all offerings for Paywalls V2.
// Paywalls V2 paywall are explicitly published so anything that
// is here is intended to be displayed.
// Also only prewarming low res urls
Expand Down

0 comments on commit ee492f3

Please sign in to comment.