Implement cancelation for replies

pull/347/head
nielsandriesse 4 years ago
parent cbc38e4af1
commit 2074d1d724

@ -197,4 +197,8 @@ extension ConversationVC : InputViewDelegate, MessageCellDelegate, ContextMenuAc
func handleScrollToBottomButtonTapped() {
scrollToBottom(isAnimated: true)
}
func handleQuoteViewCancelButtonTapped() {
snInputView.quoteDraftInfo = nil
}
}

@ -9,7 +9,7 @@
// Resending failed messages
// Linkification
// Link previews
// Canceling replies
// Fix constraints and warnings
final class ConversationVC : BaseVC, ConversationViewModelDelegate, UITableViewDataSource, UITableViewDelegate {
let thread: TSThread

@ -1,5 +1,5 @@
final class InputView : UIView, InputViewButtonDelegate, InputTextViewDelegate {
final class InputView : UIView, InputViewButtonDelegate, InputTextViewDelegate, QuoteViewDelegate {
private let delegate: InputViewDelegate
var quoteDraftInfo: (model: OWSQuotedReplyModel, isOutgoing: Bool)? { didSet { handleQuoteDraftChanged() } }
@ -98,7 +98,7 @@ final class InputView : UIView, InputViewButtonDelegate, InputTextViewDelegate {
let direction: QuoteView.Direction = quoteDraftInfo.isOutgoing ? .outgoing : .incoming
let hInset: CGFloat = 6
let maxWidth = quoteDraftContainer.bounds.width
let quoteView = QuoteView(for: quoteDraftInfo.model, direction: direction, hInset: hInset, maxWidth: maxWidth)
let quoteView = QuoteView(for: quoteDraftInfo.model, direction: direction, hInset: hInset, maxWidth: maxWidth, delegate: self)
quoteDraftContainer.addSubview(quoteView)
quoteView.pin(.left, to: .left, of: quoteDraftContainer, withInset: hInset)
quoteView.pin(.top, to: .top, of: quoteDraftContainer, withInset: 12)
@ -114,7 +114,11 @@ final class InputView : UIView, InputViewButtonDelegate, InputTextViewDelegate {
if inputViewButton == documentButton { delegate.handleDocumentButtonTapped() }
if inputViewButton == sendButton { delegate.handleSendButtonTapped() }
}
func handleQuoteViewCancelButtonTapped() {
delegate.handleQuoteViewCancelButtonTapped()
}
override func resignFirstResponder() -> Bool {
inputTextView.resignFirstResponder()
}
@ -128,4 +132,5 @@ protocol InputViewDelegate {
func handleGIFButtonTapped()
func handleDocumentButtonTapped()
func handleSendButtonTapped()
func handleQuoteViewCancelButtonTapped()
}

@ -4,6 +4,7 @@ final class QuoteView : UIView {
private let direction: Direction
private let hInset: CGFloat
private let maxWidth: CGFloat
private let delegate: QuoteViewDelegate?
private var maxBodyLabelHeight: CGFloat {
switch mode {
@ -89,6 +90,7 @@ final class QuoteView : UIView {
static let iconSize: CGFloat = 24
static let labelStackViewSpacing: CGFloat = 2
static let labelStackViewVMargin: CGFloat = 4
static let cancelButtonSize: CGFloat = 32
// MARK: Lifecycle
init(for viewItem: ConversationViewItem, direction: Direction, hInset: CGFloat, maxWidth: CGFloat) {
@ -96,15 +98,17 @@ final class QuoteView : UIView {
self.maxWidth = maxWidth
self.direction = direction
self.hInset = hInset
self.delegate = nil
super.init(frame: CGRect.zero)
setUpViewHierarchy()
}
init(for model: OWSQuotedReplyModel, direction: Direction, hInset: CGFloat, maxWidth: CGFloat) {
init(for model: OWSQuotedReplyModel, direction: Direction, hInset: CGFloat, maxWidth: CGFloat, delegate: QuoteViewDelegate) {
self.mode = .draft(model)
self.maxWidth = maxWidth
self.direction = direction
self.hInset = hInset
self.delegate = delegate
super.init(frame: CGRect.zero)
setUpViewHierarchy()
}
@ -124,7 +128,8 @@ final class QuoteView : UIView {
let labelStackViewSpacing = QuoteView.labelStackViewSpacing
let labelStackViewVMargin = QuoteView.labelStackViewVMargin
let smallSpacing = Values.smallSpacing
let availableWidth: CGFloat
let cancelButtonSize = QuoteView.cancelButtonSize
var availableWidth: CGFloat
// Subtract smallSpacing twice; once for the spacing in between the stack view elements and
// once for the trailing margin.
if !hasAttachments {
@ -132,6 +137,9 @@ final class QuoteView : UIView {
} else {
availableWidth = maxWidth - 2 * hInset - thumbnailSize - 2 * smallSpacing
}
if case .draft = mode {
availableWidth -= cancelButtonSize
}
let availableSpace = CGSize(width: availableWidth, height: .greatestFiniteMagnitude)
var body = self.body
// Main stack view
@ -197,6 +205,12 @@ final class QuoteView : UIView {
} else {
mainStackView.addArrangedSubview(bodyLabel)
}
// Cancel button
let cancelButton = UIButton(type: .custom)
cancelButton.setImage(UIImage(named: "X"), for: UIControl.State.normal)
cancelButton.set(.width, to: cancelButtonSize)
cancelButton.set(.height, to: cancelButtonSize)
cancelButton.addTarget(self, action: #selector(cancel), for: UIControl.Event.touchUpInside)
// Constraints
contentView.addSubview(mainStackView)
mainStackView.pin(to: contentView)
@ -217,5 +231,21 @@ final class QuoteView : UIView {
}
contentView.set(.height, to: contentViewHeight)
lineView.set(.height, to: contentViewHeight - 8) // Add a small amount of spacing above and below the line
if case .draft = mode {
addSubview(cancelButton)
cancelButton.center(.vertical, in: self)
cancelButton.pin(.right, to: .right, of: self)
}
}
// MARK: Interaction
@objc private func cancel() {
delegate?.handleQuoteViewCancelButtonTapped()
}
}
// MARK: Delegate
protocol QuoteViewDelegate {
func handleQuoteViewCancelButtonTapped()
}

Loading…
Cancel
Save