2022-03-17 09:42:59 +00:00
|
|
|
//
|
|
|
|
// ComposeView.swift
|
|
|
|
// SimpleX
|
|
|
|
//
|
|
|
|
// Created by Evgeny on 13/03/2022.
|
|
|
|
// Copyright © 2022 SimpleX Chat. All rights reserved.
|
|
|
|
//
|
|
|
|
|
|
|
|
import SwiftUI
|
|
|
|
|
2022-03-25 22:26:05 +04:00
|
|
|
// TODO
|
|
|
|
//enum ComposeState {
|
|
|
|
// case plain
|
|
|
|
// case quoted(quotedItem: ChatItem)
|
|
|
|
// case editing(editingItem: ChatItem)
|
|
|
|
//}
|
|
|
|
|
2022-03-17 09:42:59 +00:00
|
|
|
struct ComposeView: View {
|
2022-03-25 22:26:05 +04:00
|
|
|
@Binding var message: String
|
2022-03-17 09:42:59 +00:00
|
|
|
@Binding var quotedItem: ChatItem?
|
2022-03-25 22:26:05 +04:00
|
|
|
@Binding var editingItem: ChatItem?
|
2022-03-17 09:42:59 +00:00
|
|
|
var sendMessage: (String) -> Void
|
2022-03-25 22:26:05 +04:00
|
|
|
var resetMessage: () -> Void
|
2022-03-17 09:42:59 +00:00
|
|
|
var inProgress: Bool = false
|
|
|
|
@FocusState.Binding var keyboardVisible: Bool
|
2022-03-25 22:26:05 +04:00
|
|
|
@State var editing: Bool = false
|
2022-03-17 09:42:59 +00:00
|
|
|
|
|
|
|
var body: some View {
|
|
|
|
VStack(spacing: 0) {
|
2022-03-25 22:26:05 +04:00
|
|
|
if (quotedItem != nil) {
|
|
|
|
ContextItemView(contextItem: $quotedItem, editing: $editing)
|
|
|
|
} else if (editingItem != nil) {
|
|
|
|
ContextItemView(contextItem: $editingItem, editing: $editing, resetMessage: resetMessage)
|
|
|
|
}
|
2022-03-17 09:42:59 +00:00
|
|
|
SendMessageView(
|
|
|
|
sendMessage: sendMessage,
|
|
|
|
inProgress: inProgress,
|
2022-03-25 22:26:05 +04:00
|
|
|
message: $message,
|
|
|
|
keyboardVisible: $keyboardVisible,
|
|
|
|
editing: $editing
|
2022-03-17 09:42:59 +00:00
|
|
|
)
|
|
|
|
.background(.background)
|
|
|
|
}
|
2022-03-25 22:26:05 +04:00
|
|
|
.onChange(of: editingItem == nil) { _ in
|
|
|
|
editing = (editingItem != nil)
|
|
|
|
}
|
2022-03-17 09:42:59 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
struct ComposeView_Previews: PreviewProvider {
|
|
|
|
static var previews: some View {
|
2022-03-25 22:26:05 +04:00
|
|
|
@State var message: String = ""
|
2022-03-17 09:42:59 +00:00
|
|
|
@FocusState var keyboardVisible: Bool
|
2022-03-25 22:26:05 +04:00
|
|
|
@State var item: ChatItem? = ChatItem.getSample(1, .directSnd, .now, "hello")
|
|
|
|
@State var nilItem: ChatItem? = nil
|
2022-03-17 09:42:59 +00:00
|
|
|
|
2022-03-25 22:26:05 +04:00
|
|
|
return Group {
|
|
|
|
ComposeView(
|
|
|
|
message: $message,
|
|
|
|
quotedItem: $item,
|
|
|
|
editingItem: $nilItem,
|
|
|
|
sendMessage: { print ($0) },
|
|
|
|
resetMessage: {},
|
|
|
|
keyboardVisible: $keyboardVisible
|
|
|
|
)
|
|
|
|
ComposeView(
|
|
|
|
message: $message,
|
|
|
|
quotedItem: $nilItem,
|
|
|
|
editingItem: $item,
|
|
|
|
sendMessage: { print ($0) },
|
|
|
|
resetMessage: {},
|
|
|
|
keyboardVisible: $keyboardVisible
|
|
|
|
)
|
|
|
|
}
|
2022-03-17 09:42:59 +00:00
|
|
|
}
|
|
|
|
}
|