Skip to content

Commit f1d659c

Browse files
authored
Merge pull request #16 from fummicc1/feature/improve-loading-view-size
Improve loading view size when width or height is not specified
2 parents 05700f0 + 3615d13 commit f1d659c

File tree

2 files changed

+6
-6
lines changed

2 files changed

+6
-6
lines changed

Example/Example/DownsampleGridView.swift

+3-4
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ struct DownsampleGridView: View {
55

66
@State private var url = Util.Grid.url
77
@State private var showsDetail: Bool = false
8-
@State private var size: CGSize = .init(width: 160, height: 160)
8+
@State private var height: Double = 160
99

1010
var body: some View {
1111
VStack {
@@ -18,13 +18,12 @@ struct DownsampleGridView: View {
1818
} label: {
1919
AsyncDownSamplingImage(
2020
url: url,
21-
downsampleSize: .size(Util.Grid.bufferedImageSize)
21+
downsampleSize: .height(height)
2222
) { image in
2323
image.resizable()
2424
.aspectRatio(contentMode: .fit)
2525
.frame(
26-
width: size.width,
27-
height: size.height
26+
height: height
2827
)
2928
} onFail: { error in
3029
Text("Error: \(error.localizedDescription)")

Sources/AsyncDownSamplingImage/AsyncDownSamplingImage.swift

+3-2
Original file line numberDiff line numberDiff line change
@@ -163,8 +163,9 @@ public struct AsyncDownSamplingImage<Content: View, Placeholder: View, Fail: Vie
163163
value: loadingOpacity
164164
)
165165
.frame(
166-
width: downsampleSize.size.width,
167-
height: downsampleSize.size.height
166+
// If both width and height are not provided, treat loading image as square.
167+
width: downsampleSize.size.width ?? downsampleSize.size.height,
168+
height: downsampleSize.size.height ?? downsampleSize.size.width
168169
)
169170
.redacted(reason: .placeholder)
170171
.onAppear {

0 commit comments

Comments
 (0)