{"action":"created","issue":{"url":"https://api.github.com/repos/facebook/AsyncDisplayKit/issues/954","repository_url":"https://api.github.com/repos/facebook/AsyncDisplayKit","labels_url":"https://api.github.com/repos/facebook/AsyncDisplayKit/issues/954/labels{/name}","comments_url":"https://api.github.com/repos/facebook/AsyncDisplayKit/issues/954/comments","events_url":"https://api.github.com/repos/facebook/AsyncDisplayKit/issues/954/events","html_url":"https://github.com/facebook/AsyncDisplayKit/issues/954","id":123012919,"number":954,"title":"[Example apps] Adding custom calculated cell heights to the CustomCollectionView example.","user":{"login":"marcelofabri","id":833072,"avatar_url":"https://avatars.githubusercontent.com/u/833072?v=3","gravatar_id":"","url":"https://api.github.com/users/marcelofabri","html_url":"https://github.com/marcelofabri","followers_url":"https://api.github.com/users/marcelofabri/followers","following_url":"https://api.github.com/users/marcelofabri/following{/other_user}","gists_url":"https://api.github.com/users/marcelofabri/gists{/gist_id}","starred_url":"https://api.github.com/users/marcelofabri/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/marcelofabri/subscriptions","organizations_url":"https://api.github.com/users/marcelofabri/orgs","repos_url":"https://api.github.com/users/marcelofabri/repos","events_url":"https://api.github.com/users/marcelofabri/events{/privacy}","received_events_url":"https://api.github.com/users/marcelofabri/received_events","type":"User","site_admin":false},"labels":[{"url":"https://api.github.com/repos/facebook/AsyncDisplayKit/labels/community%20debugging","name":"community debugging","color":"009b95"},{"url":"https://api.github.com/repos/facebook/AsyncDisplayKit/labels/discussion","name":"discussion","color":"cc317c"}],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":10,"created_at":"2015-12-18T19:37:54Z","updated_at":"2016-03-22T04:15:03Z","closed_at":null,"body":"Hi,\r\n\r\nThis is my first time playing with AsyncDisplayKit, so sorry if this is a stupid question.\r\n\r\nI'm trying to modify the `CustomCollectionView` to support calculated cell heights, as the current version asks a `MosaicCollectionViewLayoutDelegate` the original cell size and I'd like to avoid it.\r\n\r\nI was able to change `_itemSizeAtIndexPath` in `MosaicCollectionViewLayout` to this:\r\n\r\n```objc\r\n- (CGSize)_itemSizeAtIndexPath:(NSIndexPath *)indexPath\r\n{\r\n  ASCollectionView *collectionView = self.collectionView;\r\n  CGSize calculatedSize = [collectionView calculatedSizeForNodeAtIndexPath:indexPath];\r\n  CGSize size = CGSizeMake([self _columnWidthForSection:indexPath.section], calculatedSize.height);\r\n  return size;\r\n}\r\n```\r\n\r\nHowever, this causes a crash unless I change the `ASCollectionView` to have `asyncDataFetching` set to  `NO`.\r\n\r\nIs this the \"right way\"? How would you do this?\r\n\r\nThanks!"},"comment":{"url":"https://api.github.com/repos/facebook/AsyncDisplayKit/issues/comments/199630921","html_url":"https://github.com/facebook/AsyncDisplayKit/issues/954#issuecomment-199630921","issue_url":"https://api.github.com/repos/facebook/AsyncDisplayKit/issues/954","id":199630921,"user":{"login":"adamastern","id":4900872,"avatar_url":"https://avatars.githubusercontent.com/u/4900872?v=3","gravatar_id":"","url":"https://api.github.com/users/adamastern","html_url":"https://github.com/adamastern","followers_url":"https://api.github.com/users/adamastern/followers","following_url":"https://api.github.com/users/adamastern/following{/other_user}","gists_url":"https://api.github.com/users/adamastern/gists{/gist_id}","starred_url":"https://api.github.com/users/adamastern/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/adamastern/subscriptions","organizations_url":"https://api.github.com/users/adamastern/orgs","repos_url":"https://api.github.com/users/adamastern/repos","events_url":"https://api.github.com/users/adamastern/events{/privacy}","received_events_url":"https://api.github.com/users/adamastern/received_events","type":"User","site_admin":false},"created_at":"2016-03-22T04:15:03Z","updated_at":"2016-03-22T04:15:03Z","body":"> I see what you're trying to achieve in interfacing with the calculatedSizeForNodeAtIndexPath: method, however, this will likely result in unwanted behavior because the layout is calculated before the cells are measured\r\n\r\n@levi in what context would this happen? My understanding is that ASCollectionView only inserts cells after the the node for the index path has been setup and measured by its dataController (usually on a background thread). This all happens through the ASRangeController delegate methods [here](https://github.com/facebook/AsyncDisplayKit/blob/master/AsyncDisplayKit/ASCollectionView.mm#L964). Any call to insert, update or delete items will then trigger a re-layout of the collection view and prepareLayout will be called again. In fact, calling numberOfSections: and numberOfItemsInSection: on ASCollectionView will only return the number of items and sections that have been loaded (and measured) by the dataController [here](https://github.com/facebook/AsyncDisplayKit/blob/master/AsyncDisplayKit/ASCollectionView.mm#L520), not the number returned by asyncDatasource \r\n \r\nI have setup a custom UICollectionViewLayout that calls : calculatedSizeForNodeAtIndexPath to get the size of the cells and it seems to work fine. What am I missing here?"}}