Skip to content

Commit

Permalink
Disable selectable text
Browse files Browse the repository at this point in the history
  • Loading branch information
mojganii committed Nov 27, 2024
1 parent 1db50d2 commit 6ed0825
Showing 1 changed file with 8 additions and 23 deletions.
31 changes: 8 additions & 23 deletions ios/MullvadVPN/Views/InfoHeaderView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ class InfoHeaderView: UIView, UITextViewDelegate {
super.init(frame: .zero)

textView.backgroundColor = .clear
textView.dataDetectorTypes = .link
textView.isSelectable = true
textView.isEditable = false
textView.isScrollEnabled = false
Expand All @@ -32,11 +31,13 @@ class InfoHeaderView: UIView, UITextViewDelegate {
textView.attributedText = makeAttributedString()
textView.linkTextAttributes = defaultLinkAttributes
textView.textContainer.lineFragmentPadding = 0
textView.isSelectable = false
textView.delegate = self

directionalLayoutMargins = .zero

addSubviews()
addTapGestureRecognizer()
}

required init?(coder: NSCoder) {
Expand Down Expand Up @@ -78,29 +79,13 @@ class InfoHeaderView: UIView, UITextViewDelegate {
}
}

func textView(
_ textView: UITextView,
shouldInteractWith URL: URL,
in characterRange: NSRange,
interaction: UITextItemInteraction
) -> Bool {
onAbout?()
return false
}

@available(iOS 17.0, *)
func textView(_ textView: UITextView, menuConfigurationFor textItem: UITextItem, defaultMenu: UIMenu) -> UITextItem
.MenuConfiguration? {
return nil
private func addTapGestureRecognizer() {
let tapGesture = UITapGestureRecognizer(target: self, action: #selector(handleTextViewTap))
textView.addGestureRecognizer(tapGesture)
}

@available(iOS 17.0, *)
func textView(_ textView: UITextView, primaryActionFor textItem: UITextItem, defaultAction: UIAction) -> UIAction? {
if case .link = textItem.content {
return UIAction { [weak self] _ in
self?.onAbout?()
}
}
return nil
@objc
private func handleTextViewTap() {
onAbout?()
}
}

0 comments on commit 6ed0825

Please sign in to comment.