Respond to CR.

This commit is contained in:
Matthew Chen 2019-03-14 13:29:40 -04:00
parent b7d3a99f39
commit 684cebf2df
3 changed files with 30 additions and 11 deletions

View file

@ -7,7 +7,8 @@ import UIKit
protocol AttachmentApprovalInputAccessoryViewDelegate: class {
func attachmentApprovalInputUpdateMediaRail()
func attachmentApprovalInputEditCaptions()
func attachmentApprovalInputStartEditingCaptions()
func attachmentApprovalInputStopEditingCaptions()
}
// MARK: -
@ -62,12 +63,7 @@ class AttachmentApprovalInputAccessoryView: UIView {
let backgroundView = UIView()
backgroundView.backgroundColor = UIColor.black.withAlphaComponent(0.6)
addSubview(backgroundView)
backgroundView.autoPinEdge(toSuperviewEdge: .top)
backgroundView.autoPinEdge(toSuperviewEdge: .leading)
backgroundView.autoPinEdge(toSuperviewEdge: .trailing)
backgroundView.autoPinEdge(toSuperviewEdge: .bottom, withInset: -200)
backgroundView.setContentHuggingLow()
backgroundView.setCompressionResistanceLow()
backgroundView.autoPinEdgesToSuperviewEdges()
currentCaptionLabel.textColor = UIColor(white: 1, alpha: 0.8)
currentCaptionLabel.font = UIFont.ows_dynamicTypeBody
@ -85,7 +81,13 @@ class AttachmentApprovalInputAccessoryView: UIView {
stackView.axis = .vertical
addSubview(stackView)
stackView.autoPinEdgesToSuperviewEdges()
stackView.autoPinEdge(toSuperviewEdge: .top)
stackView.autoPinEdge(toSuperviewEdge: .leading)
stackView.autoPinEdge(toSuperviewEdge: .trailing)
// We pin to the superview's _margin_. Otherwise the notch breaks
// the layout if you hide the keyboard in the simulator (or if the
// user uses an external keyboard).
stackView.autoPinEdge(toSuperviewMargin: .bottom)
}
// MARK: - Events
@ -94,7 +96,7 @@ class AttachmentApprovalInputAccessoryView: UIView {
guard sender.state == .recognized else {
return
}
delegate?.attachmentApprovalInputEditCaptions()
delegate?.attachmentApprovalInputStartEditingCaptions()
}
// MARK:
@ -172,4 +174,8 @@ extension AttachmentApprovalInputAccessoryView: AttachmentCaptionToolbarDelegate
delegate?.attachmentApprovalInputUpdateMediaRail()
}
public func attachmentCaptionToolbarDidComplete() {
delegate?.attachmentApprovalInputStopEditingCaptions()
}
}

View file

@ -731,7 +731,11 @@ extension AttachmentApprovalViewController: AttachmentApprovalInputAccessoryView
updateMediaRail()
}
public func attachmentApprovalInputEditCaptions() {
public func attachmentApprovalInputStartEditingCaptions() {
isEditingCaptions = true
}
public func attachmentApprovalInputStopEditingCaptions() {
isEditingCaptions = false
}
}

View file

@ -7,6 +7,7 @@ import UIKit
protocol AttachmentCaptionToolbarDelegate: class {
func attachmentCaptionToolbarDidEdit(_ attachmentCaptionToolbar: AttachmentCaptionToolbar)
func attachmentCaptionToolbarDidComplete()
}
// MARK: -
@ -107,6 +108,7 @@ class AttachmentCaptionToolbar: UIView, UITextViewDelegate {
lazy var textView: UITextView = {
let textView = buildTextView()
textView.returnKeyType = .done
textView.scrollIndicatorInsets = UIEdgeInsets(top: 5, left: 0, bottom: 5, right: 3)
return textView
@ -189,7 +191,14 @@ class AttachmentCaptionToolbar: UIView, UITextViewDelegate {
}
}
return true
// 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" {
attachmentCaptionToolbarDelegate?.attachmentCaptionToolbarDidComplete()
return false
} else {
return true
}
}
// MARK: - Helpers