"Sources/git@git.xx.network:mobile/ios/client-ios.git" did not exist on "2f9b38e823c5512ae6d98e4313b888ca7531157a"
Newer
Older
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
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
import UIKit
import Shared
final class TextInputView: UIView, UITextViewDelegate {
let internalStack = UIStackView()
var replyView = ChatInputReply()
var placeholderView = UITextView()
lazy var bubble = BubbleView(internalStack, padding: 4)
let stack = UIStackView()
let textView = UITextView()
let showActionsButton = UIButton()
let hideActionsButton = UIButton()
let sendButton = UIButton()
let audioButton = UIButton()
var maxHeight: () -> CGFloat = { 150 }
var textDidChange: (String) -> Void = { _ in }
private var computedTextHeight: CGFloat {
let textWidth = textView.frame.size.width
let size = CGSize(width: textWidth, height: .greatestFiniteMagnitude)
return textView.sizeThatFits(size).height
}
init() {
super.init(frame: .zero)
setup()
}
required init?(coder: NSCoder) { nil }
override func layoutSubviews() {
super.layoutSubviews()
updateHeight()
}
func updateHeight() {
let replyHeight = replyView.isHidden ? 0 : replyView.bounds.height
let computedTextHeight = self.computedTextHeight
let computedHeight = computedTextHeight + replyHeight
let maxHeight = self.maxHeight()
if computedHeight < maxHeight {
textView.snp.updateConstraints { $0.height.equalTo(computedTextHeight) }
textView.isScrollEnabled = false
} else {
textView.snp.updateConstraints { $0.height.equalTo(maxHeight - replyHeight) }
textView.isScrollEnabled = true
}
}
private func setup() {
replyView.isHidden = true
textView.autocorrectionType = .default
placeholderView.isUserInteractionEnabled = false
textView.font = Fonts.Mulish.semiBold.font(size: 14.0)
placeholderView.text = Localized.Chat.placeholder
placeholderView.font = Fonts.Mulish.semiBold.font(size: 14.0)
textView.backgroundColor = .clear
placeholderView.backgroundColor = .clear
textView.textColor = Asset.neutralActive.color
bubble.backgroundColor = Asset.neutralSecondary.color
placeholderView.textColor = Asset.neutralDisabled.color
showActionsButton.setImage(Asset.chatInputActionOpen.image, for: .normal)
hideActionsButton.setImage(Asset.chatInputActionClose.image, for: .normal)
audioButton.setImage(Asset.chatInputVoiceStart.image, for: .normal)
sendButton.setImage(Asset.chatSend.image, for: .normal)
showActionsButton.setContentHuggingPriority(.defaultHigh, for: .horizontal)
showActionsButton.setContentCompressionResistancePriority(.required, for: .horizontal)
hideActionsButton.setContentHuggingPriority(.defaultHigh, for: .horizontal)
hideActionsButton.setContentCompressionResistancePriority(.required, for: .horizontal)
sendButton.setContentHuggingPriority(.defaultHigh, for: .horizontal)
sendButton.setContentCompressionResistancePriority(.required, for: .horizontal)
audioButton.setContentHuggingPriority(.defaultHigh, for: .horizontal)
audioButton.setContentCompressionResistancePriority(.required, for: .horizontal)
internalStack.axis = .vertical
internalStack.addArrangedSubview(replyView)
internalStack.addArrangedSubview(textView)
textView.addSubview(placeholderView)
textView.setContentHuggingPriority(.defaultLow, for: .horizontal)
placeholderView.snp.makeConstraints { make in
make.top.equalToSuperview()
make.left.equalToSuperview()
make.height.equalToSuperview()
make.width.equalToSuperview()
}
stack.axis = .horizontal
stack.spacing = 8
stack.addArrangedSubview(showActionsButton)
stack.addArrangedSubview(hideActionsButton)
stack.addArrangedSubview(bubble)
stack.addArrangedSubview(sendButton)
stack.addArrangedSubview(audioButton)
addSubview(stack)
stack.translatesAutoresizingMaskIntoConstraints = false
NSLayoutConstraint.activate([
stack.topAnchor.constraint(equalTo: topAnchor),
stack.leadingAnchor.constraint(equalTo: leadingAnchor),
stack.trailingAnchor.constraint(equalTo: trailingAnchor),
stack.bottomAnchor.constraint(equalTo: bottomAnchor),
])
textView.delegate = self
}
func textViewDidChange(_ textView: UITextView) {
textDidChange(textView.text)
}
}