* ios api
* ios wip
* android wip
* ios files folder
* ios get address on start
* android app files folder
* ios more backend
* android more backend
* translation
* ios image without text, remove preview
* android image without text, remove preview
* fix translation
* file name in previews and w/t text
* Revert "file name in previews and w/t text"
This reverts commit 0110570e55.
* ios filename in preview
* android filename in preview
* android wider images
* ios determine width on image for correct quote width
* ios images in previews wip
* ios square image in quote
* ios: update image layout
* android images in quotes
* android remove redundant modifier
* android clip to bounds
* android - image in right side of quote
* android refactor image view
* android - refactor, align quote text top
* android fix emoji view
* fix image layout
* full screen image view, fix quote layout
* android various size
* android fixed image width
* android meta on image
* ios: add drag gesture to hide full-screen image
* android: make image-only meta white
* refactor file.stored
* android: meta icon color
* android: open chat scrolled to last unread item
* copy/share image messages
* android: full screen image
* check file is loaded
* terminal: refactor view for messages with files
* android: change to onClick, only show stored file
* android: remove close sheet bar
* android: close image view on click
* translation
* android: pass showMenu to CIImageView to show menu on long click
* increase DropDown width
Co-authored-by: Evgeny Poberezkin <2769109+epoberezkin@users.noreply.github.com>
100 lines
3.0 KiB
Swift
100 lines
3.0 KiB
Swift
//
|
|
// MsgContentView.swift
|
|
// SimpleX
|
|
//
|
|
// Created by Evgeny on 13/03/2022.
|
|
// Copyright © 2022 SimpleX Chat. All rights reserved.
|
|
//
|
|
|
|
import SwiftUI
|
|
|
|
private let uiLinkColor = UIColor(red: 0, green: 0.533, blue: 1, alpha: 1)
|
|
private let linkColor = Color(uiColor: uiLinkColor)
|
|
|
|
struct MsgContentView: View {
|
|
var content: ItemContent
|
|
var formattedText: [FormattedText]? = nil
|
|
var sender: String? = nil
|
|
var metaText: Text? = nil
|
|
var edited = false
|
|
|
|
var body: some View {
|
|
let v = messageText(content.text, formattedText, sender)
|
|
if let mt = metaText {
|
|
return v + reserveSpaceForMeta(mt, edited)
|
|
} else {
|
|
return v
|
|
}
|
|
}
|
|
|
|
private func reserveSpaceForMeta(_ meta: Text, _ edited: Bool) -> Text {
|
|
let reserve = edited ? " " : " "
|
|
return (Text(reserve) + meta)
|
|
.font(.caption)
|
|
.foregroundColor(.clear)
|
|
}
|
|
}
|
|
|
|
func messageText(_ text: String, _ formattedText: [FormattedText]?, _ sender: String?, preview: Bool = false) -> Text {
|
|
let s = text
|
|
var res: Text
|
|
if let ft = formattedText, ft.count > 0 {
|
|
res = formattText(ft[0], preview)
|
|
var i = 1
|
|
while i < ft.count {
|
|
res = res + formattText(ft[i], preview)
|
|
i = i + 1
|
|
}
|
|
} else {
|
|
res = Text(s)
|
|
}
|
|
|
|
if let s = sender {
|
|
let t = Text(s)
|
|
return (preview ? t : t.fontWeight(.medium)) + Text(": ") + res
|
|
} else {
|
|
return res
|
|
}
|
|
}
|
|
|
|
private func formattText(_ ft: FormattedText, _ preview: Bool) -> Text {
|
|
let t = ft.text
|
|
if let f = ft.format {
|
|
switch (f) {
|
|
case .bold: return Text(t).bold()
|
|
case .italic: return Text(t).italic()
|
|
case .strikeThrough: return Text(t).strikethrough()
|
|
case .snippet: return Text(t).font(.body.monospaced())
|
|
case .secret: return Text(t).foregroundColor(.clear).underline(color: .primary)
|
|
case let .colored(color): return Text(t).foregroundColor(color.uiColor)
|
|
case .uri: return linkText(t, t, preview, prefix: "")
|
|
case .email: return linkText(t, t, preview, prefix: "mailto:")
|
|
case .phone: return linkText(t, t.replacingOccurrences(of: " ", with: ""), preview, prefix: "tel:")
|
|
}
|
|
} else {
|
|
return Text(t)
|
|
}
|
|
}
|
|
|
|
private func linkText(_ s: String, _ link: String,
|
|
_ preview: Bool, prefix: String) -> Text {
|
|
preview
|
|
? Text(s).foregroundColor(linkColor).underline(color: linkColor)
|
|
: Text(AttributedString(s, attributes: AttributeContainer([
|
|
.link: NSURL(string: prefix + link) as Any,
|
|
.foregroundColor: uiLinkColor as Any
|
|
]))).underline()
|
|
}
|
|
|
|
struct MsgContentView_Previews: PreviewProvider {
|
|
static var previews: some View {
|
|
let chatItem = ChatItem.getSample(1, .directSnd, .now, "hello")
|
|
return MsgContentView(
|
|
content: chatItem.content,
|
|
formattedText: chatItem.formattedText,
|
|
sender: chatItem.memberDisplayName,
|
|
metaText: chatItem.timestampText
|
|
)
|
|
}
|
|
}
|