change in-conversation search result highlight UI to match with global search

pull/629/head
Ryan Zhao 4 years ago
parent 9a2046ea81
commit ab7bd24ad5

@ -922,7 +922,10 @@ final class ConversationVC : BaseVC, ConversationViewModelDelegate, OWSConversat
} }
func conversationSearchController(_ conversationSearchController: ConversationSearchController, didSelectMessageId interactionID: String) { func conversationSearchController(_ conversationSearchController: ConversationSearchController, didSelectMessageId interactionID: String) {
scrollToInteraction(with: interactionID) scrollToInteraction(with: interactionID, highlighted: true)
DispatchQueue.main.asyncAfter(deadline: .now() + 0.4) {
self.highlightFocusedMessageIfNeeded()
}
} }
func scrollToInteraction(with interactionID: String, position: UITableView.ScrollPosition = .middle, isAnimated: Bool = true, highlighted: Bool = false) { func scrollToInteraction(with interactionID: String, position: UITableView.ScrollPosition = .middle, isAnimated: Bool = true, highlighted: Bool = false) {

@ -146,7 +146,7 @@ final class LinkPreviewView : UIView {
// Body text view // Body text view
bodyTextViewContainer.subviews.forEach { $0.removeFromSuperview() } bodyTextViewContainer.subviews.forEach { $0.removeFromSuperview() }
if let viewItem = viewItem { if let viewItem = viewItem {
let bodyTextView = VisibleMessageCell.getBodyTextView(for: viewItem, with: maxWidth, textColor: sentLinkPreviewTextColor, searchText: delegate.lastSearchedText, delegate: delegate) let bodyTextView = VisibleMessageCell.getBodyTextView(for: viewItem, with: maxWidth, textColor: sentLinkPreviewTextColor, delegate: delegate)
self.bodyTextView = bodyTextView self.bodyTextView = bodyTextView
bodyTextViewContainer.addSubview(bodyTextView) bodyTextViewContainer.addSubview(bodyTextView)
bodyTextView.pin(to: bodyTextViewContainer, withInset: 12) bodyTextView.pin(to: bodyTextViewContainer, withInset: 12)

@ -351,7 +351,7 @@ final class VisibleMessageCell : MessageCell, LinkPreviewViewDelegate {
stackView.addArrangedSubview(quoteViewContainer) stackView.addArrangedSubview(quoteViewContainer)
} }
// Body text view // Body text view
let bodyTextView = VisibleMessageCell.getBodyTextView(for: viewItem, with: maxWidth, textColor: bodyLabelTextColor, searchText: delegate?.lastSearchedText, delegate: self) let bodyTextView = VisibleMessageCell.getBodyTextView(for: viewItem, with: maxWidth, textColor: bodyLabelTextColor, delegate: self)
self.bodyTextView = bodyTextView self.bodyTextView = bodyTextView
stackView.addArrangedSubview(bodyTextView) stackView.addArrangedSubview(bodyTextView)
// Constraints // Constraints
@ -383,7 +383,7 @@ final class VisibleMessageCell : MessageCell, LinkPreviewViewDelegate {
if let message = viewItem.interaction as? TSMessage, let body = message.body, body.count > 0 { if let message = viewItem.interaction as? TSMessage, let body = message.body, body.count > 0 {
let inset: CGFloat = 12 let inset: CGFloat = 12
let maxWidth = size.width - 2 * inset let maxWidth = size.width - 2 * inset
let bodyTextView = VisibleMessageCell.getBodyTextView(for: viewItem, with: maxWidth, textColor: bodyLabelTextColor, searchText: delegate?.lastSearchedText, delegate: self) let bodyTextView = VisibleMessageCell.getBodyTextView(for: viewItem, with: maxWidth, textColor: bodyLabelTextColor, delegate: self)
self.bodyTextView = bodyTextView self.bodyTextView = bodyTextView
stackView.addArrangedSubview(UIView(wrapping: bodyTextView, withInsets: UIEdgeInsets(top: 0, left: inset, bottom: inset, right: inset))) stackView.addArrangedSubview(UIView(wrapping: bodyTextView, withInsets: UIEdgeInsets(top: 0, left: inset, bottom: inset, right: inset)))
} }
@ -420,9 +420,8 @@ final class VisibleMessageCell : MessageCell, LinkPreviewViewDelegate {
let documentView = DocumentView(viewItem: viewItem, textColor: bodyLabelTextColor) let documentView = DocumentView(viewItem: viewItem, textColor: bodyLabelTextColor)
stackView.addArrangedSubview(documentView) stackView.addArrangedSubview(documentView)
// Body text view // Body text view
if let message = viewItem.interaction as? TSMessage, let body = message.body, body.count > 0, if let message = viewItem.interaction as? TSMessage, let body = message.body, body.count > 0 {
let delegate = delegate { // delegate should always be set at this point let bodyTextView = VisibleMessageCell.getBodyTextView(for: viewItem, with: maxWidth, textColor: bodyLabelTextColor, delegate: self)
let bodyTextView = VisibleMessageCell.getBodyTextView(for: viewItem, with: maxWidth, textColor: bodyLabelTextColor, searchText: delegate.lastSearchedText, delegate: self)
self.bodyTextView = bodyTextView self.bodyTextView = bodyTextView
stackView.addArrangedSubview(bodyTextView) stackView.addArrangedSubview(bodyTextView)
} }
@ -704,7 +703,7 @@ final class VisibleMessageCell : MessageCell, LinkPreviewViewDelegate {
return isGroupThread && viewItem.shouldShowSenderProfilePicture && senderSessionID != nil return isGroupThread && viewItem.shouldShowSenderProfilePicture && senderSessionID != nil
} }
static func getBodyTextView(for viewItem: ConversationViewItem, with availableWidth: CGFloat, textColor: UIColor, searchText: String?, delegate: UITextViewDelegate & BodyTextViewDelegate) -> UITextView { static func getBodyTextView(for viewItem: ConversationViewItem, with availableWidth: CGFloat, textColor: UIColor, delegate: UITextViewDelegate & BodyTextViewDelegate) -> UITextView {
// Take care of: // Take care of:
// Highlighting mentions // Highlighting mentions
// Linkification // Linkification
@ -718,20 +717,6 @@ final class VisibleMessageCell : MessageCell, LinkPreviewViewDelegate {
.font : UIFont.systemFont(ofSize: getFontSize(for: viewItem)) .font : UIFont.systemFont(ofSize: getFontSize(for: viewItem))
] ]
let attributedText = NSMutableAttributedString(attributedString: MentionUtilities.highlightMentions(in: message.body ?? "", isOutgoingMessage: isOutgoing, threadID: viewItem.interaction.uniqueThreadId, attributes: attributes)) let attributedText = NSMutableAttributedString(attributedString: MentionUtilities.highlightMentions(in: message.body ?? "", isOutgoingMessage: isOutgoing, threadID: viewItem.interaction.uniqueThreadId, attributes: attributes))
if let searchText = searchText, searchText.count >= ConversationSearchController.kMinimumSearchTextLength {
let normalizedSearchText = FullTextSearchFinder.normalize(text: searchText)
do {
let regex = try NSRegularExpression(pattern: NSRegularExpression.escapedPattern(for: normalizedSearchText), options: .caseInsensitive)
let matches = regex.matches(in: attributedText.string, options: .withoutAnchoringBounds, range: NSRange(location: 0, length: (attributedText.string as NSString).length))
for match in matches {
guard match.range.location + match.range.length < attributedText.length else { continue }
attributedText.addAttribute(.backgroundColor, value: UIColor.white, range: match.range)
attributedText.addAttribute(.foregroundColor, value: UIColor.black, range: match.range)
}
} catch {
// Do nothing
}
}
result.attributedText = attributedText result.attributedText = attributedText
result.dataDetectorTypes = .link result.dataDetectorTypes = .link
result.backgroundColor = .clear result.backgroundColor = .clear

Loading…
Cancel
Save