mirror of
https://github.com/simplex-chat/simplex-chat.git
synced 2026-04-23 12:25:51 +00:00
56 lines
1.6 KiB
Swift
56 lines
1.6 KiB
Swift
//
|
|
// 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
|
|
@Binding var contextItem: ChatItem?
|
|
@Binding var editing: Bool
|
|
var resetMessage: () -> Void = {}
|
|
|
|
var body: some View {
|
|
if let cxtItem = contextItem {
|
|
HStack {
|
|
contextText(cxtItem).lineLimit(3)
|
|
Spacer()
|
|
Button {
|
|
withAnimation {
|
|
contextItem = nil
|
|
if editing { resetMessage() }
|
|
}
|
|
} label: {
|
|
Image(systemName: "multiply")
|
|
}
|
|
}
|
|
.padding(12)
|
|
.frame(maxWidth: .infinity)
|
|
.background(chatItemFrameColor(cxtItem, colorScheme))
|
|
.padding(.top, 8)
|
|
} else {
|
|
EmptyView()
|
|
}
|
|
}
|
|
|
|
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 {
|
|
@State var contextItem: ChatItem? = ChatItem.getSample(1, .directSnd, .now, "hello")
|
|
@State var editing: Bool = false
|
|
return ContextItemView(contextItem: $contextItem, editing: $editing)
|
|
}
|
|
}
|