From d186e28b680aeeeda58585c6753a876065bbfb37 Mon Sep 17 00:00:00 2001 From: Jackson Harper Date: Fri, 26 Aug 2022 12:29:01 +0800 Subject: [PATCH] Use AsyncImage to fix issue with image not updating when playing audio changes --- .../App/Views/AudioPlayer/MiniPlayer.swift | 107 +++++++++--------- 1 file changed, 53 insertions(+), 54 deletions(-) diff --git a/apple/OmnivoreKit/Sources/App/Views/AudioPlayer/MiniPlayer.swift b/apple/OmnivoreKit/Sources/App/Views/AudioPlayer/MiniPlayer.swift index 03a0f5662..dfd125a45 100644 --- a/apple/OmnivoreKit/Sources/App/Views/AudioPlayer/MiniPlayer.swift +++ b/apple/OmnivoreKit/Sources/App/Views/AudioPlayer/MiniPlayer.swift @@ -67,46 +67,54 @@ public struct MiniPlayer: View { ) } + var shareButton: some View { + Button( + action: { + let shareActivity = UIActivityViewController(activityItems: [self.audioSession.localAudioUrl], applicationActivities: nil) + if let vc = UIApplication.shared.windows.first?.rootViewController { + shareActivity.popoverPresentationController?.sourceView = vc.view + // Setup share activity position on screen on bottom center + shareActivity.popoverPresentationController?.sourceRect = CGRect(x: UIScreen.main.bounds.width / 2, y: UIScreen.main.bounds.height, width: 0, height: 0) + shareActivity.popoverPresentationController?.permittedArrowDirections = UIPopoverArrowDirection.down + vc.present(shareActivity, animated: true, completion: nil) + } + }, + label: { + Image(systemName: "square.and.arrow.up") + .font(.appCallout) + .tint(.appGrayText) + } + ) + } + + var closeButton: some View { + Button( + action: { + withAnimation(.interactiveSpring()) { + self.expanded = false + } + }, + label: { + Image(systemName: "chevron.down") + .font(.appCallout) + .tint(.appGrayText) + } + ) + } + // swiftlint:disable:next function_body_length func playerContent(_ item: LinkedItem) -> some View { GeometryReader { geom in VStack { if expanded { ZStack { - Button( - action: { - withAnimation(.interactiveSpring()) { - self.expanded = false - } - }, - label: { - Image(systemName: "chevron.down") - .font(.appCallout) - .tint(.appGrayText) - } - ) - .padding(.top, 8) - .frame(maxWidth: .infinity, alignment: .leading) + closeButton + .padding(.top, 8) + .frame(maxWidth: .infinity, alignment: .leading) - Button( - action: { - let shareActivity = UIActivityViewController(activityItems: [self.audioSession.localAudioUrl], applicationActivities: nil) - if let vc = UIApplication.shared.windows.first?.rootViewController { - shareActivity.popoverPresentationController?.sourceView = vc.view - // Setup share activity position on screen on bottom center - shareActivity.popoverPresentationController?.sourceRect = CGRect(x: UIScreen.main.bounds.width / 2, y: UIScreen.main.bounds.height, width: 0, height: 0) - shareActivity.popoverPresentationController?.permittedArrowDirections = UIPopoverArrowDirection.down - vc.present(shareActivity, animated: true, completion: nil) - } - }, - label: { - Image(systemName: "square.and.arrow.up") - .font(.appCallout) - .tint(.appGrayText) - } - ) - .padding(.top, 8) - .frame(maxWidth: .infinity, alignment: .trailing) + shareButton + .padding(.top, 8) + .frame(maxWidth: .infinity, alignment: .trailing) Capsule() .fill(.gray) @@ -119,28 +127,19 @@ public struct MiniPlayer: View { Spacer(minLength: 0) HStack { - Group { - if let imageURL = item.imageURL { - let maxSize = 2 * (min(geom.size.width, geom.size.height) / 3) - let dim = expanded ? maxSize : 64 + let maxSize = 2 * (min(geom.size.width, geom.size.height) / 3) + let dim = expanded ? maxSize : 64 - AsyncLoadingImage(url: imageURL) { imageStatus in - if case let AsyncImageStatus.loaded(image) = imageStatus { - image - .resizable() - .aspectRatio(contentMode: .fill) - .frame(width: dim, height: dim) - .cornerRadius(6) - .matchedGeometryEffect(id: "ArticleArt", in: animation) - } else if case AsyncImageStatus.loading = imageStatus { - Color.appButtonBackground - .frame(width: dim, height: dim) - .cornerRadius(6) - } else { - EmptyView().frame(width: dim, height: dim, alignment: .top) - } - } - } + AsyncImage(url: item.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 !expanded {