mirror of
https://github.com/Dimillian/IceCubesApp.git
synced 2024-11-22 08:20:59 +00:00
Better status media
This commit is contained in:
parent
4cc5c8ff86
commit
e1f08514a4
4 changed files with 112 additions and 67 deletions
|
@ -397,7 +397,7 @@
|
|||
LD_RUNPATH_SEARCH_PATHS = "@executable_path/Frameworks";
|
||||
"LD_RUNPATH_SEARCH_PATHS[sdk=macosx*]" = "@executable_path/../Frameworks";
|
||||
MACOSX_DEPLOYMENT_TARGET = 13.0;
|
||||
MARKETING_VERSION = 0.0.2;
|
||||
MARKETING_VERSION = 0.0.3;
|
||||
PRODUCT_BUNDLE_IDENTIFIER = com.thomasricouard.IceCubesApp;
|
||||
PRODUCT_NAME = "$(TARGET_NAME)";
|
||||
SDKROOT = auto;
|
||||
|
@ -438,7 +438,7 @@
|
|||
LD_RUNPATH_SEARCH_PATHS = "@executable_path/Frameworks";
|
||||
"LD_RUNPATH_SEARCH_PATHS[sdk=macosx*]" = "@executable_path/../Frameworks";
|
||||
MACOSX_DEPLOYMENT_TARGET = 13.0;
|
||||
MARKETING_VERSION = 0.0.2;
|
||||
MARKETING_VERSION = 0.0.3;
|
||||
PRODUCT_BUNDLE_IDENTIFIER = com.thomasricouard.IceCubesApp;
|
||||
PRODUCT_NAME = "$(TARGET_NAME)";
|
||||
SDKROOT = auto;
|
||||
|
|
62
Packages/Status/Sources/Status/Row/StatusCardView.swift
Normal file
62
Packages/Status/Sources/Status/Row/StatusCardView.swift
Normal file
|
@ -0,0 +1,62 @@
|
|||
import SwiftUI
|
||||
import Models
|
||||
|
||||
struct StatusCardView: View {
|
||||
@Environment(\.openURL) private var openURL
|
||||
let status: AnyStatus
|
||||
|
||||
var body: some View {
|
||||
if let card = status.card, let title = card.title {
|
||||
VStack(alignment: .leading) {
|
||||
if let imageURL = card.image {
|
||||
AsyncImage(
|
||||
url: imageURL,
|
||||
content: { image in
|
||||
image.resizable()
|
||||
.aspectRatio(contentMode: .fill)
|
||||
},
|
||||
placeholder: {
|
||||
ProgressView()
|
||||
.frame(maxWidth: 40, maxHeight: 40)
|
||||
}
|
||||
)
|
||||
}
|
||||
Spacer()
|
||||
HStack {
|
||||
VStack(alignment: .leading, spacing: 6) {
|
||||
Text(title)
|
||||
.font(.headline)
|
||||
.lineLimit(3)
|
||||
if let description = card.description, !description.isEmpty {
|
||||
Text(description)
|
||||
.font(.body)
|
||||
.foregroundColor(.gray)
|
||||
.lineLimit(3)
|
||||
} else {
|
||||
Text(card.url.absoluteString)
|
||||
.font(.body)
|
||||
.foregroundColor(.gray)
|
||||
.lineLimit(3)
|
||||
}
|
||||
}
|
||||
Spacer()
|
||||
}.padding(8)
|
||||
}
|
||||
.background(Color.gray.opacity(0.15))
|
||||
.cornerRadius(16)
|
||||
.overlay(
|
||||
RoundedRectangle(cornerRadius: 16)
|
||||
.stroke(.gray.opacity(0.35), lineWidth: 1)
|
||||
)
|
||||
.onTapGesture {
|
||||
openURL(card.url)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
struct StatusCardView_Previews: PreviewProvider {
|
||||
static var previews: some View {
|
||||
StatusCardView(status: Status.placeholder())
|
||||
}
|
||||
}
|
|
@ -2,8 +2,15 @@ import SwiftUI
|
|||
import Models
|
||||
import AVKit
|
||||
|
||||
// Could have just been a state, but SwiftUI .sheet is buggy ATM without @StateObject
|
||||
class SelectedMediaSheetManager: ObservableObject {
|
||||
@Published var selectedAttachement: MediaAttachement?
|
||||
}
|
||||
|
||||
public struct StatusMediaPreviewView: View {
|
||||
public let attachements: [MediaAttachement]
|
||||
|
||||
@StateObject private var selectedMediaSheetManager = SelectedMediaSheetManager()
|
||||
|
||||
public var body: some View {
|
||||
VStack {
|
||||
|
@ -24,6 +31,24 @@ public struct StatusMediaPreviewView: View {
|
|||
}
|
||||
}
|
||||
}
|
||||
.sheet(item: $selectedMediaSheetManager.selectedAttachement) { attachement in
|
||||
VStack {
|
||||
Spacer()
|
||||
AsyncImage(
|
||||
url: attachement.url,
|
||||
content: { image in
|
||||
image
|
||||
.resizable()
|
||||
.aspectRatio(contentMode: .fit)
|
||||
},
|
||||
placeholder: {
|
||||
ProgressView()
|
||||
.frame(maxWidth: 80, maxHeight: 80)
|
||||
}
|
||||
)
|
||||
Spacer()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ViewBuilder
|
||||
|
@ -31,20 +56,29 @@ public struct StatusMediaPreviewView: View {
|
|||
if let type = attachement.supportedType {
|
||||
switch type {
|
||||
case .image:
|
||||
AsyncImage(
|
||||
url: attachement.url,
|
||||
content: { image in
|
||||
image.resizable()
|
||||
.aspectRatio(contentMode: .fit)
|
||||
.frame(maxHeight: attachements.count > 2 ? 100 : 200)
|
||||
.clipped()
|
||||
.cornerRadius(4)
|
||||
},
|
||||
placeholder: {
|
||||
ProgressView()
|
||||
.frame(maxWidth: 80, maxHeight: 80)
|
||||
Group {
|
||||
GeometryReader { proxy in
|
||||
AsyncImage(
|
||||
url: attachement.url,
|
||||
content: { image in
|
||||
image
|
||||
.resizable()
|
||||
.aspectRatio(contentMode: .fill)
|
||||
.frame(height: attachements.count > 2 ? 100 : 200)
|
||||
.frame(width: proxy.frame(in: .local).width)
|
||||
},
|
||||
placeholder: {
|
||||
ProgressView()
|
||||
.frame(maxWidth: 80, maxHeight: 80)
|
||||
}
|
||||
)
|
||||
}
|
||||
)
|
||||
.frame(height: attachements.count > 2 ? 100 : 200)
|
||||
}
|
||||
.cornerRadius(4)
|
||||
.onTapGesture {
|
||||
selectedMediaSheetManager.selectedAttachement = attachement
|
||||
}
|
||||
case .gifv:
|
||||
VideoPlayer(player: AVPlayer(url: attachement.url))
|
||||
.frame(maxHeight: attachements.count > 2 ? 100 : 200)
|
||||
|
|
|
@ -5,7 +5,6 @@ import DesignSystem
|
|||
import Network
|
||||
|
||||
public struct StatusRowView: View {
|
||||
@Environment(\.openURL) private var openURL
|
||||
@Environment(\.redactionReasons) private var reasons
|
||||
@EnvironmentObject private var client: Client
|
||||
@EnvironmentObject private var routeurPath: RouterPath
|
||||
|
@ -64,7 +63,7 @@ public struct StatusRowView: View {
|
|||
StatusMediaPreviewView(attachements: status.mediaAttachments)
|
||||
.padding(.vertical, 4)
|
||||
}
|
||||
makeCardView(status: status)
|
||||
StatusCardView(status: status)
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -85,54 +84,4 @@ public struct StatusRowView: View {
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ViewBuilder
|
||||
private func makeCardView(status: AnyStatus) -> some View {
|
||||
if let card = status.card, let title = card.title {
|
||||
VStack(alignment: .leading) {
|
||||
if let imageURL = card.image {
|
||||
AsyncImage(
|
||||
url: imageURL,
|
||||
content: { image in
|
||||
image.resizable()
|
||||
.aspectRatio(contentMode: .fill)
|
||||
},
|
||||
placeholder: {
|
||||
ProgressView()
|
||||
.frame(maxWidth: 40, maxHeight: 40)
|
||||
}
|
||||
)
|
||||
}
|
||||
Spacer()
|
||||
HStack {
|
||||
VStack(alignment: .leading, spacing: 6) {
|
||||
Text(title)
|
||||
.font(.headline)
|
||||
.lineLimit(3)
|
||||
if let description = card.description, !description.isEmpty {
|
||||
Text(description)
|
||||
.font(.body)
|
||||
.foregroundColor(.gray)
|
||||
.lineLimit(3)
|
||||
} else {
|
||||
Text(card.url.absoluteString)
|
||||
.font(.body)
|
||||
.foregroundColor(.gray)
|
||||
.lineLimit(3)
|
||||
}
|
||||
}
|
||||
Spacer()
|
||||
}.padding(8)
|
||||
}
|
||||
.background(Color.gray.opacity(0.15))
|
||||
.cornerRadius(16)
|
||||
.overlay(
|
||||
RoundedRectangle(cornerRadius: 16)
|
||||
.stroke(.gray.opacity(0.35), lineWidth: 1)
|
||||
)
|
||||
.onTapGesture {
|
||||
openURL(card.url)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue