{"action":"created","issue":{"url":"https://api.github.com/repos/facebook/AsyncDisplayKit/issues/448","labels_url":"https://api.github.com/repos/facebook/AsyncDisplayKit/issues/448/labels{/name}","comments_url":"https://api.github.com/repos/facebook/AsyncDisplayKit/issues/448/comments","events_url":"https://api.github.com/repos/facebook/AsyncDisplayKit/issues/448/events","html_url":"https://github.com/facebook/AsyncDisplayKit/issues/448","id":75227685,"number":448,"title":"layout() not being called for ASCellNode subclass, when scrolling through an ASCollectionView","user":{"login":"cbreed28","id":3528641,"avatar_url":"https://avatars.githubusercontent.com/u/3528641?v=3","gravatar_id":"","url":"https://api.github.com/users/cbreed28","html_url":"https://github.com/cbreed28","followers_url":"https://api.github.com/users/cbreed28/followers","following_url":"https://api.github.com/users/cbreed28/following{/other_user}","gists_url":"https://api.github.com/users/cbreed28/gists{/gist_id}","starred_url":"https://api.github.com/users/cbreed28/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/cbreed28/subscriptions","organizations_url":"https://api.github.com/users/cbreed28/orgs","repos_url":"https://api.github.com/users/cbreed28/repos","events_url":"https://api.github.com/users/cbreed28/events{/privacy}","received_events_url":"https://api.github.com/users/cbreed28/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":1,"created_at":"2015-05-11T13:43:19Z","updated_at":"2015-05-15T19:37:52Z","closed_at":null,"body":"I am using an ```ASCollectionView``` to display custom ```ASCellNode``` subclasses. In my ```ASCellNode``` subclass I override ```-calculateSizeThatFits:``` and ```-layout```. My custom cell consists of an image node and another custom subnode. Inside of ```-calculateSizeThatFits:``` for the cell subclass I am calling ```-measure:``` on my one custom subnode and returning a valid size. What I am seeing after calling ```-reloadData``` on my collection view is:\r\n\r\n1. ```-calculateSizeThatFits:``` is getting called on all ( say 6 ) of my cells, all of which return the correct size that I want\r\n2. ```layout()``` will be called for the first 2 visible cells, and everything works great. \r\n3. When cells 3-6 scroll onto the screen, the ASCollectionView is creating the UICollectionViewCell (_ASCollectionViewCell ) class, and adding my ASCellNode's view hierarchy too it, creating a UICollectionViewCell of the appropriate size on screen, however, ASCellNode for cell's 3-6 do not receive a ```-layout()``` call, which is causing all of my subnodes to have a bounds of CGRectZero. So essentially I am left with a bunch of blank cell in my Collection View.\r\n\r\nI feel like I am missing a step somewhere but I can't say for sure. Any thoughts / suggestions?"},"comment":{"url":"https://api.github.com/repos/facebook/AsyncDisplayKit/issues/comments/102504244","html_url":"https://github.com/facebook/AsyncDisplayKit/issues/448#issuecomment-102504244","issue_url":"https://api.github.com/repos/facebook/AsyncDisplayKit/issues/448","id":102504244,"user":{"login":"cbreed28","id":3528641,"avatar_url":"https://avatars.githubusercontent.com/u/3528641?v=3","gravatar_id":"","url":"https://api.github.com/users/cbreed28","html_url":"https://github.com/cbreed28","followers_url":"https://api.github.com/users/cbreed28/followers","following_url":"https://api.github.com/users/cbreed28/following{/other_user}","gists_url":"https://api.github.com/users/cbreed28/gists{/gist_id}","starred_url":"https://api.github.com/users/cbreed28/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/cbreed28/subscriptions","organizations_url":"https://api.github.com/users/cbreed28/orgs","repos_url":"https://api.github.com/users/cbreed28/repos","events_url":"https://api.github.com/users/cbreed28/events{/privacy}","received_events_url":"https://api.github.com/users/cbreed28/received_events","type":"User","site_admin":false},"created_at":"2015-05-15T19:37:52Z","updated_at":"2015-05-15T19:37:52Z","body":"I've been debugging this issue for awhile, looking through the ADK code base. I noticed that the ASCellNode's view was not getting laid out if the ASRangeController would add the ASCellNode to the working range before node's view received a -layoutSubview call.  So I needed a place to force a layout on the node's view to make sure that the -layoutSubviews call would be made before each cell was put on the screen. I modified the delegate hooks in side of ASCollectionView.mm to be as follows: \r\n```\r\n- (void)collectionView:(UICollectionView *)collectionView willDisplayCell:(UICollectionViewCell *)cell forItemAtIndexPath:(NSIndexPath *)indexPath\r\n{\r\n  [_rangeController visibleNodeIndexPathsDidChangeWithScrollDirection:self.scrollDirection];\r\n    \r\n  ASCellNode * node = [_dataController nodeAtIndexPath:indexPath];\r\n  [node.view setNeedsLayout];\r\n  \r\n  if ([_asyncDelegate respondsToSelector:@selector(collectionView:willDisplayNodeForItemAtIndexPath:)]) {\r\n    [_asyncDelegate collectionView:self willDisplayNodeForItemAtIndexPath:indexPath];\r\n  }\r\n}\r\n```\r\n\r\nNot sure if this violates any of the asynchronous layout properties of the node, but it seems to fix my issue by ensuring that the node's view receives a -layoutSubviews before being made visible."}}