"Done" button for caption toolbar

// FREEBIE
pull/1/head
sdkjfhsdkjhfsdlkjhfsdf 7 years ago
parent 9eb4178c6f
commit cfa147831a

@ -405,27 +405,7 @@ class CaptioningToolbar: UIView, UITextViewDelegate {
self.captioningToolbarDelegate?.captioningToolbarDidTapSend(self, captionText: self.textView.text)
}
// MARK: - UITextViewDelegate
public func textViewDidChange(_ textView: UITextView) {
Logger.debug("\(self.logTag) in \(#function)")
// compute new height assuming width is unchanged
let currentSize = textView.frame.size
let newHeight = clampedTextViewHeight(fixedWidth: currentSize.width)
if newHeight != self.textViewHeight {
Logger.debug("\(self.logTag) TextView height changed: \(self.textViewHeight) -> \(newHeight)")
self.textViewHeight = newHeight
self.setNeedsLayout()
self.layoutIfNeeded()
}
}
private func clampedTextViewHeight(fixedWidth: CGFloat) -> CGFloat {
let contentSize = textView.sizeThatFits(CGSize(width: fixedWidth, height: CGFloat.greatestFiniteMagnitude))
return Clamp(contentSize.height, kMinTextViewHeight, maxTextViewHeight)
}
// MARK: - UIView Overrides
// We do progammatic layout, explicitly computing and setting frames since autoLayout does
// not seem to work with inputAccessory views, even when forcing a layout.
@ -463,4 +443,40 @@ class CaptioningToolbar: UIView, UITextViewDelegate {
Logger.debug("After layout >>> self: \(self.frame) textView: \(self.textView.frame), sendButton:\(sendButton.frame)")
}
// MARK: - UITextViewDelegate
public func textViewDidChange(_ textView: UITextView) {
Logger.debug("\(self.logTag) in \(#function)")
// compute new height assuming width is unchanged
let currentSize = textView.frame.size
let newHeight = clampedTextViewHeight(fixedWidth: currentSize.width)
if newHeight != self.textViewHeight {
Logger.debug("\(self.logTag) TextView height changed: \(self.textViewHeight) -> \(newHeight)")
self.textViewHeight = newHeight
self.setNeedsLayout()
self.layoutIfNeeded()
}
}
public func textView(_ textView: UITextView, shouldChangeTextIn range: NSRange, replacementText text: String) -> Bool {
// Though we can wrap the text, we don't want to encourage multline captions, plus a "done" button
// allows the user to get the keyboard out of the way while in the attachment approval view.
if text == "\n" {
textView.resignFirstResponder()
return false
} else {
return true
}
}
// MARK: - Helpers
private func clampedTextViewHeight(fixedWidth: CGFloat) -> CGFloat {
let contentSize = textView.sizeThatFits(CGSize(width: fixedWidth, height: CGFloat.greatestFiniteMagnitude))
return Clamp(contentSize.height, kMinTextViewHeight, maxTextViewHeight)
}
}

Loading…
Cancel
Save