Skip to content

Commit fb0730e

Browse files
authored
Merge pull request #28 from ServerDriven/bug/Image-asset
Update SDImage to also style assets
2 parents 6bc41ea + a7b235f commit fb0730e

File tree

1 file changed

+16
-12
lines changed

1 file changed

+16
-12
lines changed

Sources/ScreenDataUI/Views/SDImage.swift

Lines changed: 16 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -68,11 +68,11 @@ public struct SDImage: View {
6868
private var progressTint: Color
6969

7070
private var screenWidth: CGFloat {
71-
#if os(iOS)
71+
#if os(iOS)
7272
UIScreen.main.bounds.width
73-
#else
73+
#else
7474
WKInterfaceDevice.current().screenBounds.width
75-
#endif
75+
#endif
7676
}
7777

7878
private var width: CGFloat {
@@ -99,16 +99,9 @@ public struct SDImage: View {
9999
Group {
100100
if let placeholderAssetName = image.assetName,
101101
let placeholder = UIImage(named: placeholderAssetName) {
102-
Image(uiImage: placeholder)
102+
styled(imageView: Image(uiImage: placeholder))
103103
} else if let loadedImage = store.image {
104-
Image(uiImage: loadedImage)
105-
.resizable()
106-
.aspectRatio(contentMode: image.aspectScale == ImageAspectScale.fit ? .fit : .fill)
107-
.frame(
108-
minWidth: 0, maxWidth: width,
109-
minHeight: 0, maxHeight: height,
110-
alignment: .center
111-
)
104+
styled(imageView: Image(uiImage: loadedImage))
112105
} else {
113106
ProgressView()
114107
.progressViewStyle(CircularProgressViewStyle(tint: progressTint))
@@ -146,4 +139,15 @@ public struct SDImage: View {
146139
imageView
147140
}
148141
}
142+
143+
private func styled(imageView: Image) -> some View {
144+
imageView
145+
.resizable()
146+
.aspectRatio(contentMode: image.aspectScale == ImageAspectScale.fit ? .fit : .fill)
147+
.frame(
148+
minWidth: 0, maxWidth: width,
149+
minHeight: 0, maxHeight: height,
150+
alignment: .center
151+
)
152+
}
149153
}

0 commit comments

Comments
 (0)