2022-03-25 22:26:05 +04:00
|
|
|
//
|
|
|
|
|
// ContextItemView.swift
|
|
|
|
|
// SimpleX
|
|
|
|
|
//
|
|
|
|
|
// Created by JRoberts on 13/03/2022.
|
|
|
|
|
// Copyright © 2022 SimpleX Chat. All rights reserved.
|
|
|
|
|
//
|
|
|
|
|
|
|
|
|
|
import SwiftUI
|
|
|
|
|
|
|
|
|
|
struct ContextItemView: View {
|
|
|
|
|
@Environment(\.colorScheme) var colorScheme
|
2022-04-25 12:44:24 +04:00
|
|
|
let contextItem: ChatItem
|
|
|
|
|
let cancelContextItem: () -> Void
|
2022-03-25 22:26:05 +04:00
|
|
|
|
|
|
|
|
var body: some View {
|
2022-04-25 12:44:24 +04:00
|
|
|
HStack {
|
|
|
|
|
contextText(contextItem).lineLimit(3)
|
|
|
|
|
Spacer()
|
|
|
|
|
Button {
|
|
|
|
|
withAnimation {
|
|
|
|
|
cancelContextItem()
|
2022-03-25 22:26:05 +04:00
|
|
|
}
|
2022-04-25 12:44:24 +04:00
|
|
|
} label: {
|
|
|
|
|
Image(systemName: "multiply")
|
2022-03-25 22:26:05 +04:00
|
|
|
}
|
|
|
|
|
}
|
2022-04-25 12:44:24 +04:00
|
|
|
.padding(12)
|
|
|
|
|
.frame(maxWidth: .infinity)
|
|
|
|
|
.background(chatItemFrameColor(contextItem, colorScheme))
|
|
|
|
|
.padding(.top, 8)
|
2022-03-25 22:26:05 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func contextText(_ cxtItem: ChatItem) -> some View {
|
|
|
|
|
if let s = cxtItem.memberDisplayName {
|
|
|
|
|
return (Text(s).fontWeight(.medium) + Text(": \(cxtItem.content.text)"))
|
|
|
|
|
} else {
|
|
|
|
|
return Text(cxtItem.content.text)
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
struct ContextItemView_Previews: PreviewProvider {
|
|
|
|
|
static var previews: some View {
|
2022-04-25 12:44:24 +04:00
|
|
|
let contextItem: ChatItem = ChatItem.getSample(1, .directSnd, .now, "hello")
|
|
|
|
|
return ContextItemView(contextItem: contextItem, cancelContextItem: {})
|
2022-03-25 22:26:05 +04:00
|
|
|
}
|
|
|
|
|
}
|