Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Empty chat input fix #82

Merged
merged 5 commits into from
Apr 22, 2019
Merged
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 12 additions & 2 deletions CriticalMass/ChatInputView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ class ChatInputView: UIView, UITextFieldDelegate {
textField.insets = UIEdgeInsets(top: 0, left: 16, bottom: 0, right: 16)
textField.enablesReturnKeyAutomatically = true
textField.returnKeyType = .send
textField.addTarget(self, action: #selector(textFieldDidChange(_:)), for: .editingChanged)
return textField
}()

Expand All @@ -31,7 +32,10 @@ class ChatInputView: UIView, UITextFieldDelegate {
button.setTitle(NSLocalizedString("chat.send", comment: ""), for: .normal)
button.setTitleColor(.chatInputSendButton, for: .normal)
button.setTitleColor(UIColor.chatInputSendButton.withAlphaComponent(0.4), for: .highlighted)
button.setTitleColor(UIColor.chatInputSendButton.withAlphaComponent(0.4), for: .disabled)
button.translatesAutoresizingMaskIntoConstraints = false
button.addTarget(self, action: #selector(didTapSendButton), for: .touchUpInside)
button.isEnabled = false
return button
}()

Expand Down Expand Up @@ -59,7 +63,7 @@ class ChatInputView: UIView, UITextFieldDelegate {
addSubview(separator)

textField.delegate = self
button.addTarget(self, action: #selector(didTapSendButton), for: .touchUpInside)

configureConstraints()
}

Expand Down Expand Up @@ -99,7 +103,13 @@ class ChatInputView: UIView, UITextFieldDelegate {
override func resignFirstResponder() -> Bool {
return textField.resignFirstResponder()
}


@objc
func textFieldDidChange(_ textField : UITextField){
if let text = textField.text {
button.isEnabled = !text.isEmpty
}
}
// MARK: UITextFieldDelegate

func textFieldShouldReturn(_ textField: UITextField) -> Bool {
Expand Down