diff --git a/apps/android/app/src/main/java/chat/simplex/app/views/TerminalView.kt b/apps/android/app/src/main/java/chat/simplex/app/views/TerminalView.kt index 4b37c86fee..116aa4d299 100644 --- a/apps/android/app/src/main/java/chat/simplex/app/views/TerminalView.kt +++ b/apps/android/app/src/main/java/chat/simplex/app/views/TerminalView.kt @@ -37,17 +37,19 @@ fun TerminalView(chatModel: ChatModel, close: () -> Unit) { @Composable fun TerminalLayout(terminalItems: List, close: () -> Unit, sendCommand: (String) -> Unit) { + var msg = remember { mutableStateOf("") } ProvideWindowInsets(windowInsetsAnimationsEnabled = true) { Scaffold( topBar = { CloseSheetBar(close) }, bottomBar = { Box(Modifier.padding(horizontal = 8.dp)) { SendMsgView( - msg = remember { mutableStateOf("") }, + msg = msg, linkPreview = remember { mutableStateOf(null) }, cancelledLinks = remember { mutableSetOf() }, parseMarkdown = { null }, - sendMessage = sendCommand + sendMessage = sendCommand, + sendEnabled = msg.value.isNotEmpty() ) } }, diff --git a/apps/android/app/src/main/java/chat/simplex/app/views/chat/ChatView.kt b/apps/android/app/src/main/java/chat/simplex/app/views/chat/ChatView.kt index 41c57167de..1b4bbf8fa8 100644 --- a/apps/android/app/src/main/java/chat/simplex/app/views/chat/ChatView.kt +++ b/apps/android/app/src/main/java/chat/simplex/app/views/chat/ChatView.kt @@ -124,6 +124,8 @@ fun ChatView(chatModel: ChatModel) { editingItem.value = null quotedItem.value = null linkPreview.value = null + chosenImage.value = null + imagePreview.value = null } }, resetMessage = { msg.value = "" }, diff --git a/apps/android/app/src/main/java/chat/simplex/app/views/chat/ComposeView.kt b/apps/android/app/src/main/java/chat/simplex/app/views/chat/ComposeView.kt index dd54790cc8..6573ee6449 100644 --- a/apps/android/app/src/main/java/chat/simplex/app/views/chat/ComposeView.kt +++ b/apps/android/app/src/main/java/chat/simplex/app/views/chat/ComposeView.kt @@ -80,7 +80,8 @@ fun ComposeView( } } ) - SendMsgView(msg, linkPreview, cancelledLinks, parseMarkdown, sendMessage, editing = editingItem.value != null) + SendMsgView(msg, linkPreview, cancelledLinks, parseMarkdown, sendMessage, + editing = editingItem.value != null, sendEnabled = msg.value.isNotEmpty() || imagePreview.value != null) } } } diff --git a/apps/android/app/src/main/java/chat/simplex/app/views/chat/SendMsgView.kt b/apps/android/app/src/main/java/chat/simplex/app/views/chat/SendMsgView.kt index 923d72faee..17065d0834 100644 --- a/apps/android/app/src/main/java/chat/simplex/app/views/chat/SendMsgView.kt +++ b/apps/android/app/src/main/java/chat/simplex/app/views/chat/SendMsgView.kt @@ -35,7 +35,8 @@ fun SendMsgView( cancelledLinks: MutableSet, parseMarkdown: (String) -> List?, sendMessage: (String) -> Unit, - editing: Boolean = false + editing: Boolean = false, + sendEnabled: Boolean = false ) { val smallFont = MaterialTheme.typography.body1.copy(color = MaterialTheme.colors.onBackground) var textStyle by remember { mutableStateOf(smallFont) } @@ -124,7 +125,7 @@ fun SendMsgView( ) { innerTextField() } - val color = if (msg.value.isNotEmpty()) MaterialTheme.colors.primary else Color.Gray + val color = if (sendEnabled) MaterialTheme.colors.primary else Color.Gray Icon( if (editing) Icons.Filled.Check else Icons.Outlined.ArrowUpward, generalGetString(R.string.icon_descr_send_message), @@ -135,7 +136,7 @@ fun SendMsgView( .clip(CircleShape) .background(color) .clickable { - if (msg.value.isNotEmpty()) { + if (sendEnabled) { sendMessage(msg.value) msg.value = "" textStyle = smallFont @@ -162,7 +163,8 @@ fun PreviewSendMsgView() { linkPreview = remember {mutableStateOf(null) }, cancelledLinks = mutableSetOf(), parseMarkdown = { null }, - sendMessage = { msg -> println(msg) } + sendMessage = { msg -> println(msg) }, + sendEnabled = true ) } } @@ -182,7 +184,8 @@ fun PreviewSendMsgViewEditing() { cancelledLinks = mutableSetOf(), sendMessage = { msg -> println(msg) }, parseMarkdown = { null }, - editing = true + editing = true, + sendEnabled = true ) } } diff --git a/apps/ios/Shared/Views/TerminalView.swift b/apps/ios/Shared/Views/TerminalView.swift index ecd4d86fbd..98d7bbd39d 100644 --- a/apps/ios/Shared/Views/TerminalView.swift +++ b/apps/ios/Shared/Views/TerminalView.swift @@ -18,7 +18,7 @@ struct TerminalView: View { @State var message: String = "" @FocusState private var keyboardVisible: Bool @State var editing: Bool = false - @State var sendEnabled: Bool = true + @State var sendEnabled: Bool = false var body: some View { VStack { @@ -76,6 +76,9 @@ struct TerminalView: View { } .navigationViewStyle(.stack) .navigationTitle("Chat console") + .onChange(of: message) { _ in + sendEnabled = !message.isEmpty + } } func scrollToBottom(_ proxy: ScrollViewProxy, animation: Animation = .default) {