Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 21 additions & 3 deletions Sources/SkipUI/SkipUI/Components/AsyncImage.swift
Original file line number Diff line number Diff line change
Expand Up @@ -94,8 +94,16 @@ public struct AsyncImage : View, Renderable {

#if SKIP
@Composable public func Render(context: ComposeContext) {
// Skip's aspectRatio modifier doesn't apply androidx.compose.foundation.layout.aspectRatio to AsyncImage
// Instead, we set it in the environment, so the Image can consume it
// If we're showing a placeholder, and the aspectRatio is in the environment, we need to apply it to the placeholder
guard let url else {
let _ = self.content(AsyncImagePhase.empty).Compose(context)
let placeholderView = self.content(AsyncImagePhase.empty)
if let (aspectRatio, contentMode) = EnvironmentValues.shared._aspectRatio {
let _ = placeholderView.aspectRatio(aspectRatio, contentMode: contentMode).Compose(context)
} else {
let _ = placeholderView.Compose(context)
}
return
}

Expand All @@ -118,13 +126,23 @@ public struct AsyncImage : View, Renderable {
.build()

SubcomposeAsyncImage(model: model, contentDescription: nil, loading: { _ in
content(AsyncImagePhase.empty).Compose(context: context)
let placeholderView = content(AsyncImagePhase.empty)
if let (aspectRatio, contentMode) = EnvironmentValues.shared._aspectRatio {
placeholderView.aspectRatio(aspectRatio, contentMode: contentMode).Compose(context: context)
} else {
placeholderView.Compose(context: context)
}
}, success: { state in
let image = Image(painter: self.painter, scale: scale)
let content = content(AsyncImagePhase.success(image))
content.Compose(context: context)
}, error: { state in
content(AsyncImagePhase.failure(ErrorException(cause: state.result.throwable))).Compose(context: context)
let placeholderView = content(AsyncImagePhase.failure(ErrorException(cause: state.result.throwable)))
if let (aspectRatio, contentMode) = EnvironmentValues.shared._aspectRatio {
placeholderView.aspectRatio(aspectRatio, contentMode: contentMode).Compose(context: context)
} else {
placeholderView.Compose(context: context)
}
})
}
#else
Expand Down