conversations-classic-ios/ConversationsClassic/View/Screens/Conversation/ConversationMessageContainer.swift

74 lines
2.3 KiB
Swift
Raw Normal View History

2024-07-11 13:59:24 +00:00
import MapKit
2024-06-27 11:39:41 +00:00
import SwiftUI
struct ConversationMessageContainer: View {
let message: Message
let isOutgoing: Bool
var body: some View {
2024-07-11 13:59:24 +00:00
if let msgText = message.body {
if msgText.isLocation {
EmbededMapView(location: msgText.getLatLon)
} else {
Text(message.body ?? "...")
.font(.body2)
.foregroundColor(.Material.Text.main)
.multilineTextAlignment(.leading)
.padding(10)
}
} else {
Text("...")
.font(.body2)
.foregroundColor(.Material.Text.main)
.multilineTextAlignment(.leading)
.padding(10)
}
2024-06-27 11:39:41 +00:00
}
}
struct MessageAttr: View {
let message: Message
var body: some View {
VStack(alignment: .leading, spacing: 0) {
Text(message.date, style: .time)
.font(.sub2)
2024-07-04 08:21:12 +00:00
.foregroundColor(.Material.Shape.separator)
2024-06-27 11:39:41 +00:00
Spacer()
if message.sentError {
Image(systemName: "exclamationmark.circle")
.font(.body3)
2024-07-04 08:21:12 +00:00
.foregroundColor(.Rainbow.red500)
2024-06-27 11:39:41 +00:00
} else if message.pending {
Image(systemName: "clock")
.font(.body3)
2024-07-04 08:21:12 +00:00
.foregroundColor(.Material.Shape.separator)
2024-06-27 11:39:41 +00:00
}
}
}
}
2024-07-11 13:59:24 +00:00
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])
}
}
}