You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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.
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.
@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.
Activity
ocrickard commentedon Apr 8, 2015
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.
siuying commentedon Apr 8, 2015
Thanks!
adamjernst commentedon Apr 8, 2015
@siuying Great point. #83 allows you to use
CKComponentActionAttributefor this, since it will now include theUIEventand sending component. You'd do the following:CKTextComponentViewusingviewContextCKTextKitRenderertextCheckingResultAtPoint:on the renderer, passing the point fetched using[UIEvent -touchesForView:]to fetch the touches and then[UITouch -locationInView:]to get a location in theCKTextComponentView.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
CKTextComponentthat would be fantastic.