Skip to content
Merged
Show file tree
Hide file tree
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
6 changes: 3 additions & 3 deletions Package.resolved

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

42 changes: 41 additions & 1 deletion Sources/BSWInterfaceKit/SwiftUI/Views/PhotoView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -72,19 +72,26 @@ public struct PhotoView: View {
private var photoView: some View {
switch photo.kind {
case .url(let url):
#if os(Android)
androidPhotoView(url: url)
#else
#if canImport(Nuke)
nukePhotoView(url: url)
#else
AsyncImage(url: url)
#endif
#endif
case .image(let image):
#if os(Android)
image.photoStyle()
#else
image
.resizable()
#endif
default:
placeholder
}
}

var isRunningTests: Bool {
#if canImport(UIKit.UIApplication)
UIApplication.shared.isRunningTests
Expand All @@ -93,6 +100,26 @@ public struct PhotoView: View {
#endif
}

// MARK: - Android

#if os(Android)
@ViewBuilder
private func androidPhotoView(url: URL) -> some View {
AsyncImage(url: url) { phase in
switch phase {
case .success(let image):
image.photoStyle()
case .failure(_):
configuration.placeholder.body()
default:
configuration.placeholder.body()
}
}
}
#endif

// MARK: - iOS

#if canImport(Nuke)
@ViewBuilder
func nukePhotoView(url: URL) -> some View {
Expand Down Expand Up @@ -180,6 +207,19 @@ extension PhotoView.Configuration: Sendable {}
extension PhotoView.Configuration.Placeholder: Sendable {}
extension PhotoView.Configuration.Placeholder.Shape: Sendable {}

// MARK: - Android image styling

#if os(Android)
private extension Image {
func photoStyle() -> some View {
self
.resizable()
.interpolation(.high)
.antialiased(true)
}
}
#endif

#if canImport(UIKit)

private extension PhotoView {
Expand Down
Loading