another.im-ios/ConversationsClassic/View/Screens/Conversation/ConversationMessageContainer.swift
2024-07-11 17:14:31 +02:00

76 lines
2.3 KiB
Swift

import MapKit
import SwiftUI
struct ConversationMessageContainer: View {
let message: Message
let isOutgoing: Bool
var body: some View {
if let msgText = message.body, msgText.isLocation {
EmbededMapView(location: msgText.getLatLon)
} else if let attachmentId = message.attachmentId {
AttachmentView(attachmentId: attachmentId)
} else {
Text(message.body ?? "...")
.font(.body2)
.foregroundColor(.Material.Text.main)
.multilineTextAlignment(.leading)
.padding(10)
}
}
}
struct MessageAttr: View {
let message: Message
var body: some View {
VStack(alignment: .leading, spacing: 0) {
Text(message.date, style: .time)
.font(.sub2)
.foregroundColor(.Material.Shape.separator)
Spacer()
if message.sentError {
Image(systemName: "exclamationmark.circle")
.font(.body3)
.foregroundColor(.Rainbow.red500)
} else if message.pending {
Image(systemName: "clock")
.font(.body3)
.foregroundColor(.Material.Shape.separator)
}
}
}
}
private struct EmbededMapView: View {
let location: CLLocationCoordinate2D
var body: some View {
Map(
coordinateRegion: .constant(MKCoordinateRegion(center: location, span: MKCoordinateSpan(latitudeDelta: 0.01, longitudeDelta: 0.01))),
interactionModes: [],
showsUserLocation: false,
userTrackingMode: .none,
annotationItems: [location],
annotationContent: { _ in
MapMarker(coordinate: location, tint: .blue)
}
)
.frame(width: Const.mapPreviewSize, height: Const.mapPreviewSize)
.cornerRadius(10)
.onTapGesture {
let mapItem = MKMapItem(placemark: MKPlacemark(coordinate: location))
mapItem.name = "Location"
mapItem.openInMaps(launchOptions: [MKLaunchOptionsDirectionsModeKey: MKLaunchOptionsDirectionsModeDriving])
}
}
}
private struct AttachmentView: View {
let attachmentId: String
var body: some View {
Text("Attachment \(attachmentId)")
}
}