Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -57,14 +57,28 @@ struct ActivityFormattableContentView: UIViewRepresentable {
super.init()
}

func textView(_ textView: UITextView, shouldInteractWith URL: URL, in characterRange: NSRange, interaction: UITextItemInteraction) -> Bool {
guard interaction == .invokeDefaultAction else {
return false
func textView(_ textView: UITextView, primaryActionFor textItem: UITextItem, defaultAction: UIAction) -> UIAction? {
guard case let .link(URL) = textItem.content else {
return nil
}

return UIAction { [weak self] _ in
self?.routeTo(URL)
}
}

func textView(_ textView: UITextView, menuConfigurationFor textItem: UITextItem, defaultMenu: UIMenu) -> UITextItem.MenuConfiguration? {
if case .link = textItem.content {
return nil
}

return .init(menu: defaultMenu)
}

private func routeTo(_ URL: URL) {
// Get the top view controller to create content coordinator
guard let viewController = UIViewController.topViewController else {
return false
return
}

let contentCoordinator = DefaultContentCoordinator(
Expand All @@ -78,8 +92,6 @@ struct ActivityFormattableContentView: UIViewRepresentable {
)

router.routeTo(URL)

return false
}
}
}
24 changes: 15 additions & 9 deletions WordPress/Classes/ViewRelated/Cells/ExpandableCell.swift
Original file line number Diff line number Diff line change
Expand Up @@ -76,15 +76,21 @@ class ExpandableCell: WPReusableTableViewCell, NibLoadable {
}

extension ExpandableCell: UITextViewDelegate {
func textView(_ textView: UITextView, shouldInteractWith URL: URL, in characterRange: NSRange, interaction: UITextItemInteraction) -> Bool {
switch interaction {
case .invokeDefaultAction:
urlCallback?(URL)
return false
case .preview, .presentActions:
return true
@unknown default:
fatalError()
func textView(_ textView: UITextView, primaryActionFor textItem: UITextItem, defaultAction: UIAction) -> UIAction? {
guard case let .link(URL) = textItem.content else {
return defaultAction
}

return UIAction { [weak self] _ in
self?.urlCallback?(URL)
}
}

func textView(_ textView: UITextView, menuConfigurationFor textItem: UITextItem, defaultMenu: UIMenu) -> UITextItem.MenuConfiguration? {
if case .link = textItem.content {
return nil
}

return .init(menu: defaultMenu)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -119,9 +119,22 @@ class NoteBlockTextTableViewCell: NoteBlockTableViewCell, RichTextViewDataSource

// MARK: - RichTextView Data Source

func textView(_ textView: UITextView, shouldInteractWith URL: URL, in characterRange: NSRange, interaction: UITextItemInteraction) -> Bool {
onUrlClick?(URL)
return false
func textView(_ textView: UITextView, primaryActionFor textItem: UITextItem, defaultAction: UIAction) -> UIAction? {
guard case let .link(URL) = textItem.content else {
return nil
}

return UIAction { [weak self] _ in
self?.onUrlClick?(URL)
}
}

func textView(_ textView: UITextView, menuConfigurationFor textItem: UITextItem, defaultMenu: UIMenu) -> UITextItem.MenuConfiguration? {
if case .link = textItem.content {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Were you able to get these menus to work? I'm long-pressing on the links in notifications, and func textView(_ textView: UITextView, menuConfigurationFor textItem: UITextItem, defaultMenu: UIMenu) -> UITextItem.MenuConfiguration? { doesn't seem to be called, and it shows the standard menu instead of the URL-related menu. I'm not sure if it's a regression from the PR or something else.

Screen.Recording.2025-09-23.at.3.20.33.PM.mov

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The trunk branch also behaves like that. The original deprecated function is also not called when long-pressing on links. I think that may have something to do with the RichTextView type.

return nil
}

return .init(menu: defaultMenu)
}

func textView(_ textView: UITextView, didPressLink link: URL) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -259,12 +259,12 @@ import UniformTypeIdentifiers
delegate?.textViewDidChangeSelection?(textView)
}

open func textView(_ textView: UITextView, shouldInteractWith URL: URL, in characterRange: NSRange, interaction: UITextItemInteraction) -> Bool {
return delegate?.textView?(textView, shouldInteractWith: URL, in: characterRange, interaction: interaction) ?? true
open func textView(_ textView: UITextView, primaryActionFor textItem: UITextItem, defaultAction: UIAction) -> UIAction? {
delegate?.textView?(textView, primaryActionFor: textItem, defaultAction: defaultAction)
}

open func textView(_ textView: UITextView, shouldInteractWith textAttachment: NSTextAttachment, in characterRange: NSRange, interaction: UITextItemInteraction) -> Bool {
return delegate?.textView?(textView, shouldInteractWith: textAttachment, in: characterRange, interaction: interaction) ?? true
public func textView(_ textView: UITextView, menuConfigurationFor textItem: UITextItem, defaultMenu: UIMenu) -> UITextItem.MenuConfiguration? {
delegate?.textView?(textView, menuConfigurationFor: textItem, defaultMenu: defaultMenu)
}

// MARK: - Private Properites
Expand Down