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,6 +77,23 @@ 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:
|
||||||
|
if let size = size(for: attachement) {
|
||||||
|
let newSize = imageSize(from: size,
|
||||||
|
newWidth: UIScreen.main.bounds.width - (DS.Constants.layoutPadding * 2))
|
||||||
|
LazyImage(url: attachement.url) { state in
|
||||||
|
if let image = state.image {
|
||||||
|
image
|
||||||
|
.resizingMode(.aspectFill)
|
||||||
|
.cornerRadius(4)
|
||||||
|
.frame(width: newSize.width, height: newSize.height)
|
||||||
|
} else {
|
||||||
|
RoundedRectangle(cornerRadius: 4)
|
||||||
|
.fill(Color.gray)
|
||||||
|
.frame(width: newSize.width, height: newSize.height)
|
||||||
|
.shimmering()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} else {
|
||||||
AsyncImage(
|
AsyncImage(
|
||||||
url: attachement.url,
|
url: attachement.url,
|
||||||
content: { image in
|
content: { image in
|
||||||
|
@ -74,8 +107,8 @@ public struct StatusMediaPreviewView: View {
|
||||||
.fill(Color.gray)
|
.fill(Color.gray)
|
||||||
.frame(height: imageMaxHeight)
|
.frame(height: imageMaxHeight)
|
||||||
.shimmering()
|
.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