Skip to content

Tapping links in CKTextComponent? #74

Closed

Description

@siuying

Any hint on how we should do to handle tap or long tap on text or URL in CKTextComponent?

I cannot set a delegate for UITextView, and cannot find anything similar in CKTextComponentView / CKTextComponentViewControlTracker?

What I currently doing is add a gesture recognizer and attach it to CKTextComponentView, and find the corresponding attributed text at user tap position. This work except I cannot get text highlighted as user click on the link.

Activity

  1. ocrickard commented on Apr 8, 2015

    @ocrickard
    Contributor

    CKTextComponentView is a subclass of UIControl so you can add target/actions for control events and use the text checking result API to grab the data you want, but you're right it's not super straight-forward how you would add link tapping. We use a convenience API internally that simply provides a selector to call with an action context object. I'll see if I can get that added to the open source version.

  2. siuying commented on Apr 8, 2015

    @siuying
    Author

    Thanks!

  3. adamjernst commented on Apr 8, 2015

    @adamjernst
    Contributor

    @siuying Great point. #83 allows you to use CKComponentActionAttribute for this, since it will now include the UIEvent and sending component. You'd do the following:

    • Get the sending component's underlying CKTextComponentView using viewContext
    • Get the view's CKTextKitRenderer
    • Call textCheckingResultAtPoint: on the renderer, passing the point fetched using [UIEvent -touchesForView:] to fetch the touches and then [UITouch -locationInView:] to get a location in the CKTextComponentView.

    This is pretty tedious. Internally we have a helper that wraps this up. If you wanted to add some built-in capability for this to CKTextComponent that would be fantastic.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions