From 684cebf2df9496ce3b7f9c9ecf0e9b25933c2bcc Mon Sep 17 00:00:00 2001 From: Matthew Chen Date: Thu, 14 Mar 2019 13:29:40 -0400 Subject: [PATCH] Respond to CR. --- ...AttachmentApprovalInputAccessoryView.swift | 24 ++++++++++++------- .../AttachmentApprovalViewController.swift | 6 ++++- .../AttachmentCaptionToolbar.swift | 11 ++++++++- 3 files changed, 30 insertions(+), 11 deletions(-) diff --git a/SignalMessaging/ViewControllers/AttachmentApproval/AttachmentApprovalInputAccessoryView.swift b/SignalMessaging/ViewControllers/AttachmentApproval/AttachmentApprovalInputAccessoryView.swift index 57f89c27c..b983274e2 100644 --- a/SignalMessaging/ViewControllers/AttachmentApproval/AttachmentApprovalInputAccessoryView.swift +++ b/SignalMessaging/ViewControllers/AttachmentApproval/AttachmentApprovalInputAccessoryView.swift @@ -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() + } } diff --git a/SignalMessaging/ViewControllers/AttachmentApproval/AttachmentApprovalViewController.swift b/SignalMessaging/ViewControllers/AttachmentApproval/AttachmentApprovalViewController.swift index 6c9612508..6d7451bcf 100644 --- a/SignalMessaging/ViewControllers/AttachmentApproval/AttachmentApprovalViewController.swift +++ b/SignalMessaging/ViewControllers/AttachmentApproval/AttachmentApprovalViewController.swift @@ -731,7 +731,11 @@ extension AttachmentApprovalViewController: AttachmentApprovalInputAccessoryView updateMediaRail() } - public func attachmentApprovalInputEditCaptions() { + public func attachmentApprovalInputStartEditingCaptions() { isEditingCaptions = true } + + public func attachmentApprovalInputStopEditingCaptions() { + isEditingCaptions = false + } } diff --git a/SignalMessaging/ViewControllers/AttachmentApproval/AttachmentCaptionToolbar.swift b/SignalMessaging/ViewControllers/AttachmentApproval/AttachmentCaptionToolbar.swift index 0187053d9..1e7f7c1c7 100644 --- a/SignalMessaging/ViewControllers/AttachmentApproval/AttachmentCaptionToolbar.swift +++ b/SignalMessaging/ViewControllers/AttachmentApproval/AttachmentCaptionToolbar.swift @@ -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