feat: restore media description text field
This commit is contained in:
parent
82abc68486
commit
1e71f0c147
|
@ -11,6 +11,8 @@ import SwiftUI
|
|||
import Introspect
|
||||
import AVKit
|
||||
import MastodonAsset
|
||||
import MastodonLocalization
|
||||
import Introspect
|
||||
|
||||
public struct AttachmentView: View {
|
||||
|
||||
|
@ -21,11 +23,35 @@ public struct AttachmentView: View {
|
|||
}
|
||||
|
||||
public var body: some View {
|
||||
Color.clear.aspectRatio(358.0/232.0, contentMode: .fill)
|
||||
.overlay(
|
||||
ZStack {
|
||||
let image = viewModel.thumbnail ?? .placeholder(color: .secondarySystemFill)
|
||||
Image(uiImage: image)
|
||||
.resizable()
|
||||
.aspectRatio(contentMode: .fill)
|
||||
}
|
||||
)
|
||||
.overlay(
|
||||
ZStack {
|
||||
Color.clear
|
||||
.overlay(
|
||||
VStack(alignment: .leading) {
|
||||
let placeholder: String = {
|
||||
switch viewModel.output {
|
||||
case .image: return L10n.Scene.Compose.Attachment.descriptionPhoto
|
||||
case .video: return L10n.Scene.Compose.Attachment.descriptionVideo
|
||||
case nil: return ""
|
||||
}
|
||||
}()
|
||||
Spacer()
|
||||
TextField(placeholder, text: $viewModel.caption)
|
||||
.textFieldStyle(.plain)
|
||||
.foregroundColor(.white)
|
||||
.placeholder(placeholder, when: viewModel.caption.isEmpty)
|
||||
.padding(8)
|
||||
}
|
||||
)
|
||||
|
||||
// loading…
|
||||
if viewModel.output == nil, viewModel.error == nil {
|
||||
|
@ -144,6 +170,32 @@ public struct AttachmentView: View {
|
|||
}
|
||||
}
|
||||
} // end ZStack
|
||||
)
|
||||
} // end body
|
||||
|
||||
}
|
||||
|
||||
// https://stackoverflow.com/a/57715771/3797903
|
||||
extension View {
|
||||
fileprivate func placeholder<Content: View>(
|
||||
when shouldShow: Bool,
|
||||
alignment: Alignment = .leading,
|
||||
@ViewBuilder placeholder: () -> Content) -> some View {
|
||||
|
||||
ZStack(alignment: alignment) {
|
||||
placeholder().opacity(shouldShow ? 1 : 0)
|
||||
self
|
||||
}
|
||||
}
|
||||
|
||||
fileprivate func placeholder(
|
||||
_ text: String,
|
||||
when shouldShow: Bool,
|
||||
alignment: Alignment = .leading) -> some View {
|
||||
|
||||
placeholder(when: shouldShow, alignment: alignment) {
|
||||
Text(text)
|
||||
.foregroundColor(.white.opacity(0.7))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -125,6 +125,21 @@ extension MastodonStatusPublisher: StatusPublisher {
|
|||
}
|
||||
attachmentIDs.append(attachment.id)
|
||||
|
||||
let caption = attachmentViewModel.caption
|
||||
guard !caption.isEmpty else { continue }
|
||||
|
||||
_ = try await api.updateMedia(
|
||||
domain: authContext.mastodonAuthenticationBox.domain,
|
||||
attachmentID: attachment.id,
|
||||
query: .init(
|
||||
file: nil,
|
||||
thumbnail: nil,
|
||||
description: caption,
|
||||
focus: nil
|
||||
),
|
||||
mastodonAuthenticationBox: authContext.mastodonAuthenticationBox
|
||||
).singleOutput()
|
||||
|
||||
// TODO: allow background upload
|
||||
// let attachment = try await attachmentViewModel.upload(context: uploadContext)
|
||||
// let attachmentID = attachment.id
|
||||
|
|
|
@ -219,10 +219,7 @@ extension ComposeContentView {
|
|||
var mediaView: some View {
|
||||
VStack(spacing: 16) {
|
||||
ForEach(viewModel.attachmentViewModels, id: \.self) { attachmentViewModel in
|
||||
Color.clear.aspectRatio(358.0/232.0, contentMode: .fill)
|
||||
.overlay(
|
||||
AttachmentView(viewModel: attachmentViewModel)
|
||||
)
|
||||
.clipShape(Rectangle())
|
||||
.badgeView(
|
||||
Button {
|
||||
|
|
Loading…
Reference in New Issue