mirror of
https://github.com/Dimillian/IceCubesApp.git
synced 2024-11-26 02:01:02 +00:00
Use Nuke if possible for featured media in status
This commit is contained in:
parent
45eafeb119
commit
f339692d3c
1 changed files with 47 additions and 14 deletions
|
@ -4,6 +4,7 @@ import Env
|
||||||
import Shimmer
|
import Shimmer
|
||||||
import Nuke
|
import Nuke
|
||||||
import NukeUI
|
import NukeUI
|
||||||
|
import DesignSystem
|
||||||
|
|
||||||
public struct StatusMediaPreviewView: View {
|
public struct StatusMediaPreviewView: View {
|
||||||
@EnvironmentObject private var quickLook: QuickLook
|
@EnvironmentObject private var quickLook: QuickLook
|
||||||
|
@ -11,6 +12,7 @@ public struct StatusMediaPreviewView: View {
|
||||||
public let attachements: [MediaAttachement]
|
public let attachements: [MediaAttachement]
|
||||||
|
|
||||||
@State private var isQuickLookLoading: Bool = false
|
@State private var isQuickLookLoading: Bool = false
|
||||||
|
@State private var width: CGFloat = 0
|
||||||
|
|
||||||
private var imageMaxHeight: CGFloat {
|
private var imageMaxHeight: CGFloat {
|
||||||
if attachements.count == 1 {
|
if attachements.count == 1 {
|
||||||
|
@ -19,6 +21,20 @@ public struct StatusMediaPreviewView: View {
|
||||||
return attachements.count > 2 ? 100 : 200
|
return attachements.count > 2 ? 100 : 200
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private func size(for media: MediaAttachement) -> CGSize? {
|
||||||
|
if let width = media.meta?.original.width,
|
||||||
|
let height = media.meta?.original.height {
|
||||||
|
return .init(width: CGFloat(width), height: CGFloat(height))
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
private func imageSize(from: CGSize, newWidth: CGFloat) -> CGSize {
|
||||||
|
let ratio = newWidth / from.width
|
||||||
|
let newHeight = from.height * ratio
|
||||||
|
return .init(width: newWidth, height: newHeight)
|
||||||
|
}
|
||||||
|
|
||||||
public var body: some View {
|
public var body: some View {
|
||||||
Group {
|
Group {
|
||||||
if attachements.count == 1, let attachement = attachements.first {
|
if attachements.count == 1, let attachement = attachements.first {
|
||||||
|
@ -61,21 +77,38 @@ public struct StatusMediaPreviewView: View {
|
||||||
private func makeFeaturedImagePreview(attachement: MediaAttachement) -> some View {
|
private func makeFeaturedImagePreview(attachement: MediaAttachement) -> some View {
|
||||||
switch attachement.supportedType {
|
switch attachement.supportedType {
|
||||||
case .image:
|
case .image:
|
||||||
AsyncImage(
|
if let size = size(for: attachement) {
|
||||||
url: attachement.url,
|
let newSize = imageSize(from: size,
|
||||||
content: { image in
|
newWidth: UIScreen.main.bounds.width - (DS.Constants.layoutPadding * 2))
|
||||||
image
|
LazyImage(url: attachement.url) { state in
|
||||||
.resizable()
|
if let image = state.image {
|
||||||
.aspectRatio(contentMode: .fill)
|
image
|
||||||
.cornerRadius(4)
|
.resizingMode(.aspectFill)
|
||||||
},
|
.cornerRadius(4)
|
||||||
placeholder: {
|
.frame(width: newSize.width, height: newSize.height)
|
||||||
RoundedRectangle(cornerRadius: 4)
|
} else {
|
||||||
.fill(Color.gray)
|
RoundedRectangle(cornerRadius: 4)
|
||||||
.frame(height: imageMaxHeight)
|
.fill(Color.gray)
|
||||||
.shimmering()
|
.frame(width: newSize.width, height: newSize.height)
|
||||||
|
.shimmering()
|
||||||
|
}
|
||||||
}
|
}
|
||||||
)
|
} else {
|
||||||
|
AsyncImage(
|
||||||
|
url: attachement.url,
|
||||||
|
content: { image in
|
||||||
|
image
|
||||||
|
.resizable()
|
||||||
|
.aspectRatio(contentMode: .fill)
|
||||||
|
.cornerRadius(4)
|
||||||
|
},
|
||||||
|
placeholder: {
|
||||||
|
RoundedRectangle(cornerRadius: 4)
|
||||||
|
.fill(Color.gray)
|
||||||
|
.frame(height: imageMaxHeight)
|
||||||
|
.shimmering()
|
||||||
|
})
|
||||||
|
}
|
||||||
case .gifv:
|
case .gifv:
|
||||||
VideoPlayerView(viewModel: .init(url: attachement.url))
|
VideoPlayerView(viewModel: .init(url: attachement.url))
|
||||||
.frame(height: imageMaxHeight)
|
.frame(height: imageMaxHeight)
|
||||||
|
|
Loading…
Reference in a new issue