mirror of
https://github.com/simplex-chat/simplex-chat.git
synced 2026-04-20 12:55:58 +00:00
* 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>
118 lines
4.1 KiB
Swift
118 lines
4.1 KiB
Swift
//
|
|
// TerminalView.swift
|
|
// SimpleX
|
|
//
|
|
// Created by Evgeny Poberezkin on 27/01/2022.
|
|
// Copyright © 2022 SimpleX Chat. All rights reserved.
|
|
//
|
|
|
|
import SwiftUI
|
|
|
|
private let terminalFont = Font.custom("Menlo", size: 16)
|
|
|
|
private let maxItemSize: Int = 50000
|
|
|
|
struct TerminalView: View {
|
|
@EnvironmentObject var chatModel: ChatModel
|
|
@State var inProgress: Bool = false
|
|
@State var message: String = ""
|
|
@FocusState private var keyboardVisible: Bool
|
|
@State var editing: Bool = false
|
|
@State var sendEnabled: Bool = false
|
|
|
|
var body: some View {
|
|
VStack {
|
|
ScrollViewReader { proxy in
|
|
ScrollView {
|
|
LazyVStack {
|
|
ForEach(chatModel.terminalItems) { item in
|
|
NavigationLink {
|
|
let s = item.details
|
|
ScrollView {
|
|
Text(s.prefix(maxItemSize))
|
|
.padding()
|
|
}
|
|
.toolbar {
|
|
ToolbarItem(placement: .navigationBarTrailing) {
|
|
Button { showShareSheet(items: [s]) } label: {
|
|
Image(systemName: "square.and.arrow.up")
|
|
}
|
|
}
|
|
}
|
|
} label: {
|
|
HStack {
|
|
Text(item.id.formatted(date: .omitted, time: .standard))
|
|
Text(item.label)
|
|
.frame(maxWidth: .infinity, maxHeight: 30, alignment: .leading)
|
|
}
|
|
.font(terminalFont)
|
|
.padding(.horizontal)
|
|
}
|
|
}
|
|
.onAppear { scrollToBottom(proxy) }
|
|
.onChange(of: chatModel.terminalItems.count) { _ in scrollToBottom(proxy) }
|
|
.onChange(of: keyboardVisible) { _ in
|
|
if keyboardVisible {
|
|
DispatchQueue.main.asyncAfter(deadline: .now() + 0.25) {
|
|
scrollToBottom(proxy, animation: .easeInOut(duration: 1))
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
Spacer()
|
|
|
|
SendMessageView(
|
|
sendMessage: sendMessage,
|
|
inProgress: inProgress,
|
|
message: $message,
|
|
keyboardVisible: $keyboardVisible,
|
|
editing: $editing,
|
|
sendEnabled: $sendEnabled
|
|
)
|
|
.padding(.horizontal, 12)
|
|
}
|
|
}
|
|
.navigationViewStyle(.stack)
|
|
.navigationTitle("Chat console")
|
|
.onChange(of: message) { _ in
|
|
sendEnabled = !message.isEmpty
|
|
}
|
|
}
|
|
|
|
func scrollToBottom(_ proxy: ScrollViewProxy, animation: Animation = .default) {
|
|
if let id = chatModel.terminalItems.last?.id {
|
|
withAnimation(animation) {
|
|
proxy.scrollTo(id, anchor: .bottom)
|
|
}
|
|
}
|
|
}
|
|
|
|
func sendMessage(_ cmdStr: String) {
|
|
let cmd = ChatCommand.string(cmdStr)
|
|
DispatchQueue.global().async {
|
|
Task {
|
|
inProgress = true
|
|
_ = await chatSendCmd(cmd)
|
|
inProgress = false
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
struct TerminalView_Previews: PreviewProvider {
|
|
static var previews: some View {
|
|
let chatModel = ChatModel()
|
|
chatModel.terminalItems = [
|
|
.resp(.now, ChatResponse.response(type: "contactSubscribed", json: "{}")),
|
|
.resp(.now, ChatResponse.response(type: "newChatItem", json: "{}"))
|
|
]
|
|
return NavigationView {
|
|
TerminalView()
|
|
.environmentObject(chatModel)
|
|
}
|
|
|
|
}
|
|
}
|