From cad8df31a3c42a9d5d3e3af59590b5732e4ffdf1 Mon Sep 17 00:00:00 2001 From: Jackson Harper Date: Fri, 23 Sep 2022 18:27:34 +0800 Subject: [PATCH] Better placeholder image when no URL is set --- .../App/Views/AudioPlayer/MiniPlayer.swift | 39 ++++++++++++++----- 1 file changed, 29 insertions(+), 10 deletions(-) diff --git a/apple/OmnivoreKit/Sources/App/Views/AudioPlayer/MiniPlayer.swift b/apple/OmnivoreKit/Sources/App/Views/AudioPlayer/MiniPlayer.swift index 39552b85f..db8231b93 100644 --- a/apple/OmnivoreKit/Sources/App/Views/AudioPlayer/MiniPlayer.swift +++ b/apple/OmnivoreKit/Sources/App/Views/AudioPlayer/MiniPlayer.swift @@ -157,16 +157,35 @@ public struct MiniPlayer: View { let maxSize = 2 * (min(geom.size.width, geom.size.height) / 3) let dim = expanded ? maxSize : 64 - AsyncImage(url: itemAudioProperties.imageURL) { image in - image - .resizable() - .aspectRatio(contentMode: .fill) - .frame(width: dim, height: dim) - .cornerRadius(6) - } placeholder: { - Color.appButtonBackground - .frame(width: dim, height: dim) - .cornerRadius(6) + if let imageURL = itemAudioProperties.imageURL { + AsyncImage(url: imageURL) { phase in + if let image = phase.image { + image + .resizable() + .aspectRatio(contentMode: .fill) + .frame(width: dim, height: dim) + .cornerRadius(6) + } else if phase.error != nil { + Color.appButtonBackground + .frame(width: dim, height: dim) + .cornerRadius(6) + } else { + Color.appButtonBackground + .frame(width: dim, height: dim) + .cornerRadius(6) + } + } + } else { + ZStack(alignment: .center) { + Color.appButtonBackground + .frame(width: dim, height: dim) + .cornerRadius(6) + + Image(systemName: "headphones") + .resizable() + .aspectRatio(contentMode: .fit) + .frame(width: dim / 2, height: dim / 2) + } } if !expanded {