Skip to content

Commit

Permalink
[ABW-1983] Fix Broken Image Placeholder (#676)
Browse files Browse the repository at this point in the history
  • Loading branch information
kugel3 committed Aug 17, 2023
1 parent 9689e2e commit 1cb3f40
Showing 1 changed file with 19 additions and 9 deletions.
28 changes: 19 additions & 9 deletions Sources/Core/DesignSystem/Components/Thumbnails.swift
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ public struct TokenThumbnail: View {
Image(asset: AssetResource.xrd)
.resizable()
case let .known(url):
LoadableImage(url: url, size: .fixedSize(size), placeholders: .init(brokenImage: .standard)) {
LoadableImage(url: url, size: .fixedSize(size)) {
placeholder
}
case .unknown:
Expand Down Expand Up @@ -233,18 +233,33 @@ public struct LoadableImage<Placeholder: View>: View {
case let .asset(imageAsset):
Image(asset: imageAsset)
.resizable()
.frame(width: brokenImageSize.width, height: brokenImageSize.height)
case .brokenImage:
HStack(spacing: 0) {
Spacer(minLength: .small1)
Spacer(minLength: .small2)

Image(asset: AssetResource.brokenImagePlaceholder)
.resizable()
.aspectRatio(1, contentMode: .fit)
.frame(minWidth: .medium2, minHeight: .medium2)
.frame(maxWidth: .large1, maxHeight: .large1)

Spacer(minLength: .small1)
Spacer(minLength: .small2)
}
.frame(height: .imagePlaceholderHeight)
.frame(width: brokenImageSize.width, height: brokenImageSize.height)
.background(.app.gray4)
case .standard:
placeholder
.frame(width: brokenImageSize.width, height: brokenImageSize.height)
}
}

private var brokenImageSize: (width: CGFloat?, height: CGFloat) {
switch sizingBehaviour {
case let .fixedSize(size, _):
return (size.frame.width, size.frame.height)
case .flexible:
return (nil, .imagePlaceholderHeight)
}
}
}
Expand All @@ -253,11 +268,6 @@ public struct LoadableImage<Placeholder: View>: View {
public enum LoadableImageSize: Equatable {
case fixedSize(HitTargetSize, mode: ImageResizingMode = .aspectFill)
case flexible(minAspect: CGFloat, maxAspect: CGFloat)

var isFixedSize: Bool {
if case .fixedSize = self { return true }
return false
}
}

// MARK: - LoadableImagePlaceholderBehaviour
Expand Down

0 comments on commit 1cb3f40

Please sign in to comment.