Respond to CR.

pull/2/head
Matthew Chen 7 years ago
parent b7d3a99f39
commit 684cebf2df

@ -7,7 +7,8 @@ import UIKit
protocol AttachmentApprovalInputAccessoryViewDelegate: class { protocol AttachmentApprovalInputAccessoryViewDelegate: class {
func attachmentApprovalInputUpdateMediaRail() func attachmentApprovalInputUpdateMediaRail()
func attachmentApprovalInputEditCaptions() func attachmentApprovalInputStartEditingCaptions()
func attachmentApprovalInputStopEditingCaptions()
} }
// MARK: - // MARK: -
@ -62,12 +63,7 @@ class AttachmentApprovalInputAccessoryView: UIView {
let backgroundView = UIView() let backgroundView = UIView()
backgroundView.backgroundColor = UIColor.black.withAlphaComponent(0.6) backgroundView.backgroundColor = UIColor.black.withAlphaComponent(0.6)
addSubview(backgroundView) addSubview(backgroundView)
backgroundView.autoPinEdge(toSuperviewEdge: .top) backgroundView.autoPinEdgesToSuperviewEdges()
backgroundView.autoPinEdge(toSuperviewEdge: .leading)
backgroundView.autoPinEdge(toSuperviewEdge: .trailing)
backgroundView.autoPinEdge(toSuperviewEdge: .bottom, withInset: -200)
backgroundView.setContentHuggingLow()
backgroundView.setCompressionResistanceLow()
currentCaptionLabel.textColor = UIColor(white: 1, alpha: 0.8) currentCaptionLabel.textColor = UIColor(white: 1, alpha: 0.8)
currentCaptionLabel.font = UIFont.ows_dynamicTypeBody currentCaptionLabel.font = UIFont.ows_dynamicTypeBody
@ -85,7 +81,13 @@ class AttachmentApprovalInputAccessoryView: UIView {
stackView.axis = .vertical stackView.axis = .vertical
addSubview(stackView) 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 // MARK: - Events
@ -94,7 +96,7 @@ class AttachmentApprovalInputAccessoryView: UIView {
guard sender.state == .recognized else { guard sender.state == .recognized else {
return return
} }
delegate?.attachmentApprovalInputEditCaptions() delegate?.attachmentApprovalInputStartEditingCaptions()
} }
// MARK: // MARK:
@ -172,4 +174,8 @@ extension AttachmentApprovalInputAccessoryView: AttachmentCaptionToolbarDelegate
delegate?.attachmentApprovalInputUpdateMediaRail() delegate?.attachmentApprovalInputUpdateMediaRail()
} }
public func attachmentCaptionToolbarDidComplete() {
delegate?.attachmentApprovalInputStopEditingCaptions()
}
} }

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

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

Loading…
Cancel
Save