Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Second link not accessible when VoiceOver is enabled. #818

Open
nservidio opened this issue Jan 28, 2022 · 0 comments
Open

Second link not accessible when VoiceOver is enabled. #818

nservidio opened this issue Jan 28, 2022 · 0 comments

Comments

@nservidio
Copy link

iPhone 12 mini
iOS 15.2.1

Steps to repro:

  1. Configure a TTTAttributedLabel with an NSAttributedString.
  2. Add 2 links to the text.
  3. Make sure the font of the attributed string wraps the text onto a second line.
  4. Enable VoiceOver.

Expected: Both links are accessible via VoiceOver.
Actual: Only the first link is accessible via VoiceOver.


To test you can create a single view app with a Storyboard and replace the ViewController code with the following:

Code snippet
import UIKit
import TTTAttributedLabel
import PureLayout

class ViewController: UIViewController, TTTAttributedLabelDelegate {

    let labelText = "I have read and understand Foo's Privacy Policy. I accept the Foo Terms of Use."
    let privacyPolicyLinkText = "Privacy Policy"
    let privacyPolicyLinkURL = URL(string: "https://www.privacy.com")!
    let termsLinkText = "Terms of Use"
    let termsLinkURL = URL(string: "https://www.terms.com")!

    override func viewDidLoad() {
        super.viewDidLoad()
        view.backgroundColor = .white

        let label = TTTAttributedLabel(forAutoLayout: ())
        label.numberOfLines = 0
        label.delegate = self

        view.addSubview(label)
        label.autoAlignAxis(toSuperviewAxis: .horizontal)
        label.autoPinEdge(toSuperviewEdge: .leading, withInset: 20)
        label.autoPinEdge(toSuperviewEdge: .trailing, withInset: 20)

        let attributedString = NSAttributedString(string: labelText,
                                                  attributes: [
                                                    NSAttributedString.Key.font: UIFont.systemFont(ofSize: 16)])

        label.setText(attributedString)
        label.addLink(to: privacyPolicyLinkURL, with: (labelText as NSString).range(of: privacyPolicyLinkText))
        label.addLink(to: termsLinkURL, with: (labelText as NSString).range(of: termsLinkText))
    }

    func attributedLabel(_ label: TTTAttributedLabel!, didSelectLinkWith url: URL!) {
        let alert = UIAlertController(title: "Alert",
                                      message: "Tapped link: \(url.absoluteString)",
                                      preferredStyle: .alert)
        let action = UIAlertAction(title: "Ok", style: .default, handler: nil)
        alert.addAction(action)
        present(alert, animated: true, completion: nil)
    }
}

Here is the Podfile being used. I used PureLayout in addition to TTTAttributedLabel.

Podfile
# Uncomment the next line to define a global platform for your project
# platform :ios, '9.0'

target 'AttributedLabelLinkBug' do
  # Comment the next line if you don't want to use dynamic frameworks
  use_frameworks!

  pod 'TTTAttributedLabel'
  pod 'PureLayout'

  target 'AttributedLabelLinkBugTests' do
    inherit! :search_paths
    # Pods for testing
  end

  target 'AttributedLabelLinkBugUITests' do
    # Pods for testing
  end

end

Here is a video of the issue:
https://user-images.githubusercontent.com/7491869/151636127-948eec72-c3a4-4452-b698-c1815e6c6bec.mp4

Notice how the links are clickable when VO is not enabled.


The technical issue seems to be in the boundingRectForCharacterRange method. boundingRectForGlyphRange does not return the correct CGRect for the second link.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant