-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathBasicInputBarView.swift
49 lines (43 loc) · 1.34 KB
/
BasicInputBarView.swift
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
//
// BasicInputBarView.swift
//
//
// Created by Jack Hogan on 11/22/21.
//
import SwiftUI
public struct BasicInputBarView: View {
@Binding private var message: String
private let onSend: () -> Void
public init(message: Binding<String>, onSend: @escaping () -> Void) {
self._message = message
self.onSend = onSend
}
public var body: some View {
HStack {
// Hack to get TextEditor to have resizeable height
Text(message)
.foregroundColor(.clear)
.padding(8)
.lineLimit(4)
.frame(maxWidth: .infinity)
.overlay(
TextEditor(text: $message)
.cornerRadius(4)
)
Button("Send") {
onSend()
}
.buttonStyle(.borderedProminent)
.disabled(message.isEmpty)
.animation(.easeInOut(duration: 0.2), value: message.isEmpty)
}
.padding([.top, .bottom], 8)
.padding([.leading, .trailing])
.background(Color(uiColor: .systemGray6).edgesIgnoringSafeArea([.leading, .trailing, .bottom]))
}
}
private struct BasicInputBarView_Previews: PreviewProvider {
static var previews: some View {
BasicInputBarView(message: .constant("Test"), onSend: {})
}
}