Fixed UX around tapping link in messages which contain attachments

pull/946/head
Morgan Pretty 4 months ago
parent 3f19c776d9
commit a9b3756a44

@ -897,11 +897,30 @@ extension ConversationVC:
return
}
/// Takes the `cell` and a `targetView` and returns `true` if the user tapped a link in the cell body text instead
/// of the `targetView`
func handleLinkTapIfNeeded(cell: UITableViewCell, targetView: UIView?) -> Bool {
let locationInTargetView: CGPoint = cell.convert(cellLocation, to: targetView)
guard
let visibleCell: VisibleMessageCell = cell as? VisibleMessageCell,
targetView?.bounds.contains(locationInTargetView) != true,
visibleCell.bodyTappableLabel?.containsLinks == true
else { return false }
let tappableLabelPoint: CGPoint = cell.convert(cellLocation, to: visibleCell.bodyTappableLabel)
visibleCell.bodyTappableLabel?.handleTouch(at: tappableLabelPoint)
return true
}
switch cellViewModel.cellType {
case .voiceMessage: viewModel.playOrPauseAudio(for: cellViewModel)
case .mediaMessage:
guard let albumView: MediaAlbumView = (cell as? VisibleMessageCell)?.albumView else { return }
guard
let albumView: MediaAlbumView = (cell as? VisibleMessageCell)?.albumView,
!handleLinkTapIfNeeded(cell: cell, targetView: albumView)
else { return }
// Figure out which of the media views was tapped
let locationInAlbumView: CGPoint = cell.convert(cellLocation, to: albumView)
@ -982,6 +1001,7 @@ extension ConversationVC:
case .audio:
guard
!handleLinkTapIfNeeded(cell: cell, targetView: (cell as? VisibleMessageCell)?.documentView),
let attachment: Attachment = cellViewModel.attachments?.first,
let originalFilePath: String = attachment.originalFilePath
else { return }
@ -993,6 +1013,7 @@ extension ConversationVC:
case .genericAttachment:
guard
!handleLinkTapIfNeeded(cell: cell, targetView: (cell as? VisibleMessageCell)?.documentView),
let attachment: Attachment = cellViewModel.attachments?.first,
let originalFilePath: String = attachment.originalFilePath
else { return }

@ -14,6 +14,7 @@ final class VisibleMessageCell: MessageCell, TappableLabelDelegate {
var albumView: MediaAlbumView?
var quoteView: QuoteView?
var linkPreviewView: LinkPreviewView?
var documentView: DocumentView?
var bodyTappableLabel: TappableLabel?
var voiceMessageView: VoiceMessageView?
var audioStateChanged: ((TimeInterval, Bool) -> ())?
@ -471,6 +472,7 @@ final class VisibleMessageCell: MessageCell, TappableLabelDelegate {
albumView = nil
quoteView = nil
linkPreviewView = nil
documentView = nil
bodyTappableLabel = nil
// Handle the deleted state first (it's much simpler than the others)
@ -649,6 +651,7 @@ final class VisibleMessageCell: MessageCell, TappableLabelDelegate {
// Document view
let documentView = DocumentView(attachment: attachment, textColor: bodyLabelTextColor)
self.documentView = documentView
stackView.addArrangedSubview(documentView)
// Body text view

@ -1,4 +1,6 @@
// Copyright © 2022 Rangeproof Pty Ltd. All rights reserved.
//
// stringlint:disable
import Foundation
@ -8,7 +10,7 @@ public extension Dictionary {
return "[ " + map { key, value in
let keyDescription = String(describing: key)
let valueDescription = String(describing: value)
let maxLength = 20
let maxLength = 50
let truncatedValueDescription = valueDescription.count > maxLength ? valueDescription.prefix(maxLength) + "..." : valueDescription
return keyDescription + " : " + truncatedValueDescription
}.joined(separator: ", ") + " ]"

@ -1,4 +1,6 @@
// Copyright © 2022 Rangeproof Pty Ltd. All rights reserved.
//
// stringlint:disable
import Foundation

Loading…
Cancel
Save