{"action":"created","issue":{"url":"https://api.github.com/repos/facebook/componentkit/issues/272","labels_url":"https://api.github.com/repos/facebook/componentkit/issues/272/labels{/name}","comments_url":"https://api.github.com/repos/facebook/componentkit/issues/272/comments","events_url":"https://api.github.com/repos/facebook/componentkit/issues/272/events","html_url":"https://github.com/facebook/componentkit/pull/272","id":90968078,"number":272,"title":"Add parameter for layout manager subclass to CKTextKitContext","user":{"login":"itsthejb","id":557391,"avatar_url":"https://avatars.githubusercontent.com/u/557391?v=3","gravatar_id":"","url":"https://api.github.com/users/itsthejb","html_url":"https://github.com/itsthejb","followers_url":"https://api.github.com/users/itsthejb/followers","following_url":"https://api.github.com/users/itsthejb/following{/other_user}","gists_url":"https://api.github.com/users/itsthejb/gists{/gist_id}","starred_url":"https://api.github.com/users/itsthejb/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/itsthejb/subscriptions","organizations_url":"https://api.github.com/users/itsthejb/orgs","repos_url":"https://api.github.com/users/itsthejb/repos","events_url":"https://api.github.com/users/itsthejb/events{/privacy}","received_events_url":"https://api.github.com/users/itsthejb/received_events","type":"User","site_admin":false},"labels":[{"url":"https://api.github.com/repos/facebook/componentkit/labels/CLA%20Signed","name":"CLA Signed","color":"009900"},{"url":"https://api.github.com/repos/facebook/componentkit/labels/GH%20Review:%20review-needed","name":"GH Review: review-needed","color":"fef2c0"}],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":1,"created_at":"2015-06-25T13:38:37Z","updated_at":"2015-06-25T14:14:04Z","closed_at":null,"pull_request":{"url":"https://api.github.com/repos/facebook/componentkit/pulls/272","html_url":"https://github.com/facebook/componentkit/pull/272","diff_url":"https://github.com/facebook/componentkit/pull/272.diff","patch_url":"https://github.com/facebook/componentkit/pull/272.patch"},"body":"Hi all,\r\n\r\nMe again :wink: Proposed minor feature addition here to support the following use case:\r\n\r\nWe have a \"tokens\" view component which displays tappable tokens with a rounded corner background like this:\r\n\r\n![screen shot 2015-06-25 at 15 30 00](https://cloud.githubusercontent.com/assets/557391/8355368/2476e83a-1b4f-11e5-8699-e75120f01424.png)\r\n\r\n`NSAttributedString` of course has `NSBackgroundColorAttributeName`, but this only allows colouring with sharp rectangles. In order to do this you need an `NSLayoutManager` subclass and override one of its drawing methods.\r\n\r\nSince `CKTextComponent` doesn't provide enough customisation to its underlying renderer (which is perfectly fine), the approach I've taken is to create a `CKTextKitContext` within my component's custom view in order to create the `NSTextContainer` which is eventually used to create a `UITextView` right at the end of the layout stage. This is very important in order to run into thread safety problems with the rest of CK.\r\n\r\nSoooo... In order to facilitate all of this I've added an optional (default to `NSLayoutManager`) `layoutManagerSubclass` parameter to `CKTextKitContext`.\r\n\r\nMost likely adding *another* parameter isn't exactly desirably, but I couldn't see any other way to cleanly add this functionality. Since this is an internal class which is rarely used directly, this seems like NBD, but of course I welcome feedback.\r\n\r\nCouple of simple test cases included, and others updated of course.\r\n\r\nThanks!"},"comment":{"url":"https://api.github.com/repos/facebook/componentkit/issues/comments/115272055","html_url":"https://github.com/facebook/componentkit/pull/272#issuecomment-115272055","issue_url":"https://api.github.com/repos/facebook/componentkit/issues/272","id":115272055,"user":{"login":"ocrickard","id":857665,"avatar_url":"https://avatars.githubusercontent.com/u/857665?v=3","gravatar_id":"","url":"https://api.github.com/users/ocrickard","html_url":"https://github.com/ocrickard","followers_url":"https://api.github.com/users/ocrickard/followers","following_url":"https://api.github.com/users/ocrickard/following{/other_user}","gists_url":"https://api.github.com/users/ocrickard/gists{/gist_id}","starred_url":"https://api.github.com/users/ocrickard/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/ocrickard/subscriptions","organizations_url":"https://api.github.com/users/ocrickard/orgs","repos_url":"https://api.github.com/users/ocrickard/repos","events_url":"https://api.github.com/users/ocrickard/events{/privacy}","received_events_url":"https://api.github.com/users/ocrickard/received_events","type":"User","site_admin":false},"created_at":"2015-06-25T14:14:04Z","updated_at":"2015-06-25T14:14:04Z","body":"Before I review, a quick comment:\r\n\r\nIn your description here you say that you're creating a `UITextView` at the end of the layout stage.  Do you mean that within the scope of `-computeLayoutThatFits:`?  When used with a CKComponentDataSource that method will be invoked on a bg thread, and so creation of a UITextView (while it may work 99% of the time) will probably crash.\r\n\r\nAlso, the reason we don't expose these classes is that there are tons of threading concerns when interacting with TextKit on a bg thread due to some unprotected global caches that they use under the hood.  We've tried to lock the usage where we know we will hit contention points, but it's just too easy to shoot yourself in the foot with these on a different thread.\r\n\r\nNow I'm off to review!"}}