2022-01-29 23:37:02 +00:00
|
|
|
//
|
|
|
|
// SendMessageView.swift
|
|
|
|
// SimpleX
|
|
|
|
//
|
|
|
|
// Created by Evgeny Poberezkin on 29/01/2022.
|
|
|
|
// Copyright © 2022 SimpleX Chat. All rights reserved.
|
|
|
|
//
|
|
|
|
|
|
|
|
import SwiftUI
|
|
|
|
|
|
|
|
struct SendMessageView: View {
|
|
|
|
var sendMessage: (String) -> Void
|
|
|
|
var inProgress: Bool = false
|
|
|
|
@State var command: String = ""
|
|
|
|
|
|
|
|
var body: some View {
|
|
|
|
HStack {
|
|
|
|
TextField("Message...", text: $command)
|
2022-01-31 21:28:07 +00:00
|
|
|
.textFieldStyle(.roundedBorder)
|
|
|
|
.textInputAutocapitalization(.never)
|
|
|
|
.disableAutocorrection(true)
|
|
|
|
.onSubmit(submit)
|
2022-01-29 23:37:02 +00:00
|
|
|
|
|
|
|
if (inProgress) {
|
|
|
|
ProgressView()
|
|
|
|
.frame(width: 40, height: 20, alignment: .center)
|
|
|
|
} else {
|
|
|
|
Button("Send", action :submit)
|
|
|
|
.disabled(command.isEmpty)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
.frame(minHeight: 30)
|
2022-01-31 21:28:07 +00:00
|
|
|
.padding(12)
|
2022-01-29 23:37:02 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func submit() {
|
|
|
|
sendMessage(command)
|
|
|
|
command = ""
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
struct SendMessageView_Previews: PreviewProvider {
|
|
|
|
static var previews: some View {
|
|
|
|
SendMessageView(sendMessage: { print ($0) })
|
|
|
|
}
|
|
|
|
}
|