mirror of
https://github.com/Dimillian/IceCubesApp.git
synced 2025-02-02 19:22:18 +00:00
Support medium display mode for card view
This commit is contained in:
parent
00e7f29a11
commit
2828550531
2 changed files with 30 additions and 7 deletions
|
@ -10,36 +10,58 @@ public struct StatusRowCardView: View {
|
||||||
@Environment(\.isInCaptureMode) private var isInCaptureMode: Bool
|
@Environment(\.isInCaptureMode) private var isInCaptureMode: Bool
|
||||||
|
|
||||||
@EnvironmentObject private var theme: Theme
|
@EnvironmentObject private var theme: Theme
|
||||||
|
|
||||||
let card: Card
|
let card: Card
|
||||||
|
|
||||||
public init(card: Card) {
|
public init(card: Card) {
|
||||||
self.card = card
|
self.card = card
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private var maxWidth: CGFloat? {
|
||||||
|
if theme.statusDisplayStyle == .medium {
|
||||||
|
return 300
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
private func imageWidthFor(proxy: GeometryProxy) -> CGFloat {
|
||||||
|
if theme.statusDisplayStyle == .medium, let maxWidth {
|
||||||
|
return maxWidth
|
||||||
|
}
|
||||||
|
return proxy.frame(in: .local).width
|
||||||
|
}
|
||||||
|
|
||||||
|
private var imageHeight: CGFloat {
|
||||||
|
if theme.statusDisplayStyle == .medium {
|
||||||
|
return 100
|
||||||
|
}
|
||||||
|
return 200
|
||||||
|
}
|
||||||
|
|
||||||
public var body: some View {
|
public var body: some View {
|
||||||
if let title = card.title, let url = URL(string: card.url) {
|
if let title = card.title, let url = URL(string: card.url) {
|
||||||
VStack(alignment: .leading) {
|
VStack(alignment: .leading) {
|
||||||
if let imageURL = card.image, !isInCaptureMode {
|
if let imageURL = card.image, !isInCaptureMode {
|
||||||
GeometryReader { proxy in
|
GeometryReader { proxy in
|
||||||
let processors: [ImageProcessing] = [.resize(size: .init(width: proxy.frame(in: .local).width,
|
let width = imageWidthFor(proxy: proxy)
|
||||||
height: 200))]
|
let processors: [ImageProcessing] = [.resize(size: .init(width: width, height: imageHeight))]
|
||||||
LazyImage(url: imageURL) { state in
|
LazyImage(url: imageURL) { state in
|
||||||
if let image = state.image {
|
if let image = state.image {
|
||||||
image
|
image
|
||||||
.resizable()
|
.resizable()
|
||||||
.aspectRatio(contentMode: .fill)
|
.aspectRatio(contentMode: .fill)
|
||||||
.frame(height: 200)
|
.frame(height: imageHeight)
|
||||||
.frame(maxWidth: proxy.frame(in: .local).width)
|
.frame(maxWidth: width)
|
||||||
.clipped()
|
.clipped()
|
||||||
} else if state.isLoading {
|
} else if state.isLoading {
|
||||||
Rectangle()
|
Rectangle()
|
||||||
.fill(Color.gray)
|
.fill(Color.gray)
|
||||||
.frame(height: 200)
|
.frame(height: imageHeight)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
.processors(processors)
|
.processors(processors)
|
||||||
}
|
}
|
||||||
.frame(height: 200)
|
.frame(height: imageHeight)
|
||||||
}
|
}
|
||||||
HStack {
|
HStack {
|
||||||
VStack(alignment: .leading, spacing: 6) {
|
VStack(alignment: .leading, spacing: 6) {
|
||||||
|
@ -60,6 +82,7 @@ public struct StatusRowCardView: View {
|
||||||
Spacer()
|
Spacer()
|
||||||
}.padding(8)
|
}.padding(8)
|
||||||
}
|
}
|
||||||
|
.frame(maxWidth: maxWidth)
|
||||||
.fixedSize(horizontal: false, vertical: true)
|
.fixedSize(horizontal: false, vertical: true)
|
||||||
.background(theme.secondaryBackgroundColor)
|
.background(theme.secondaryBackgroundColor)
|
||||||
.cornerRadius(16)
|
.cornerRadius(16)
|
||||||
|
|
|
@ -52,7 +52,7 @@ struct StatusRowContentView: View {
|
||||||
if let card = status.card,
|
if let card = status.card,
|
||||||
!viewModel.isEmbedLoading,
|
!viewModel.isEmbedLoading,
|
||||||
!isCompact,
|
!isCompact,
|
||||||
theme.statusDisplayStyle == .large,
|
theme.statusDisplayStyle != .compact,
|
||||||
status.content.statusesURLs.isEmpty,
|
status.content.statusesURLs.isEmpty,
|
||||||
status.mediaAttachments.isEmpty
|
status.mediaAttachments.isEmpty
|
||||||
{
|
{
|
||||||
|
|
Loading…
Reference in a new issue