mirror of
https://github.com/Dimillian/IceCubesApp.git
synced 2024-06-18 13:10:39 +00:00
Embed Media card in Button
This commit is contained in:
parent
ed5b3d7e0f
commit
d41eca867b
|
@ -39,79 +39,83 @@ public struct StatusRowCardView: View {
|
||||||
}
|
}
|
||||||
|
|
||||||
public var body: some View {
|
public var body: some View {
|
||||||
if let title = card.title, let url = URL(string: card.url) {
|
Button {
|
||||||
VStack(alignment: .leading) {
|
if let url = URL(string: card.url) {
|
||||||
if let imageURL = card.image, !isInCaptureMode {
|
|
||||||
GeometryReader { proxy in
|
|
||||||
let width = imageWidthFor(proxy: proxy)
|
|
||||||
let processors: [ImageProcessing] = [.resize(size: .init(width: width, height: imageHeight))]
|
|
||||||
LazyImage(url: imageURL) { state in
|
|
||||||
if let image = state.image {
|
|
||||||
image
|
|
||||||
.resizable()
|
|
||||||
.aspectRatio(contentMode: .fill)
|
|
||||||
.frame(height: imageHeight)
|
|
||||||
.frame(maxWidth: width)
|
|
||||||
.clipped()
|
|
||||||
} else if state.isLoading {
|
|
||||||
Rectangle()
|
|
||||||
.fill(Color.gray)
|
|
||||||
.frame(height: imageHeight)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
.processors(processors)
|
|
||||||
// This image is decorative
|
|
||||||
.accessibilityHidden(true)
|
|
||||||
}
|
|
||||||
.frame(height: imageHeight)
|
|
||||||
}
|
|
||||||
HStack {
|
|
||||||
VStack(alignment: .leading, spacing: 6) {
|
|
||||||
Text(title)
|
|
||||||
.font(.scaledHeadline)
|
|
||||||
.lineLimit(3)
|
|
||||||
if let description = card.description, !description.isEmpty {
|
|
||||||
Text(description)
|
|
||||||
.font(.scaledBody)
|
|
||||||
.foregroundColor(.gray)
|
|
||||||
.lineLimit(3)
|
|
||||||
}
|
|
||||||
Text(url.host() ?? url.absoluteString)
|
|
||||||
.font(.scaledFootnote)
|
|
||||||
.foregroundColor(theme.tintColor)
|
|
||||||
.lineLimit(1)
|
|
||||||
}
|
|
||||||
Spacer()
|
|
||||||
}.padding(16)
|
|
||||||
}
|
|
||||||
.frame(maxWidth: maxWidth)
|
|
||||||
.fixedSize(horizontal: false, vertical: true)
|
|
||||||
.background(theme.secondaryBackgroundColor)
|
|
||||||
.cornerRadius(16)
|
|
||||||
.overlay(
|
|
||||||
RoundedRectangle(cornerRadius: 16)
|
|
||||||
.stroke(.gray.opacity(0.35), lineWidth: 1)
|
|
||||||
)
|
|
||||||
.onTapGesture {
|
|
||||||
openURL(url)
|
openURL(url)
|
||||||
}
|
}
|
||||||
.contextMenu {
|
} label: {
|
||||||
ShareLink(item: url) {
|
if let title = card.title, let url = URL(string: card.url) {
|
||||||
Label("status.card.share", systemImage: "square.and.arrow.up")
|
VStack(alignment: .leading) {
|
||||||
|
if let imageURL = card.image, !isInCaptureMode {
|
||||||
|
GeometryReader { proxy in
|
||||||
|
let width = imageWidthFor(proxy: proxy)
|
||||||
|
let processors: [ImageProcessing] = [.resize(size: .init(width: width, height: imageHeight))]
|
||||||
|
LazyImage(url: imageURL) { state in
|
||||||
|
if let image = state.image {
|
||||||
|
image
|
||||||
|
.resizable()
|
||||||
|
.aspectRatio(contentMode: .fill)
|
||||||
|
.frame(height: imageHeight)
|
||||||
|
.frame(maxWidth: width)
|
||||||
|
.clipped()
|
||||||
|
} else if state.isLoading {
|
||||||
|
Rectangle()
|
||||||
|
.fill(Color.gray)
|
||||||
|
.frame(height: imageHeight)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
.processors(processors)
|
||||||
|
// This image is decorative
|
||||||
|
.accessibilityHidden(true)
|
||||||
|
}
|
||||||
|
.frame(height: imageHeight)
|
||||||
|
}
|
||||||
|
HStack {
|
||||||
|
VStack(alignment: .leading, spacing: 6) {
|
||||||
|
Text(title)
|
||||||
|
.font(.scaledHeadline)
|
||||||
|
.lineLimit(3)
|
||||||
|
if let description = card.description, !description.isEmpty {
|
||||||
|
Text(description)
|
||||||
|
.font(.scaledBody)
|
||||||
|
.foregroundColor(.gray)
|
||||||
|
.lineLimit(3)
|
||||||
|
}
|
||||||
|
Text(url.host() ?? url.absoluteString)
|
||||||
|
.font(.scaledFootnote)
|
||||||
|
.foregroundColor(theme.tintColor)
|
||||||
|
.lineLimit(1)
|
||||||
|
}
|
||||||
|
Spacer()
|
||||||
|
}.padding(16)
|
||||||
}
|
}
|
||||||
Button { openURL(url) } label: {
|
.frame(maxWidth: maxWidth)
|
||||||
Label("status.action.view-in-browser", systemImage: "safari")
|
.fixedSize(horizontal: false, vertical: true)
|
||||||
}
|
.background(theme.secondaryBackgroundColor)
|
||||||
Divider()
|
.cornerRadius(16)
|
||||||
Button {
|
.overlay(
|
||||||
UIPasteboard.general.url = url
|
RoundedRectangle(cornerRadius: 16)
|
||||||
} label: {
|
.stroke(.gray.opacity(0.35), lineWidth: 1)
|
||||||
Label("status.card.copy", systemImage: "doc.on.doc")
|
)
|
||||||
|
.contextMenu {
|
||||||
|
ShareLink(item: url) {
|
||||||
|
Label("status.card.share", systemImage: "square.and.arrow.up")
|
||||||
|
}
|
||||||
|
Button { openURL(url) } label: {
|
||||||
|
Label("status.action.view-in-browser", systemImage: "safari")
|
||||||
|
}
|
||||||
|
Divider()
|
||||||
|
Button {
|
||||||
|
UIPasteboard.general.url = url
|
||||||
|
} label: {
|
||||||
|
Label("status.card.copy", systemImage: "doc.on.doc")
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
.accessibilityElement(children: .combine)
|
||||||
|
.accessibilityAddTraits(.isLink)
|
||||||
|
.accessibilityRemoveTraits(.isStaticText)
|
||||||
}
|
}
|
||||||
.accessibilityElement(children: .combine)
|
|
||||||
.accessibilityAddTraits(.isLink)
|
|
||||||
.accessibilityRemoveTraits(.isStaticText)
|
|
||||||
}
|
}
|
||||||
|
.buttonStyle(.plain)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue