TextureGroup / Texture

Smooth asynchronous user interfaces for iOS apps.
https://texturegroup.org/
Other
8k stars 1.29k forks source link

constrainedSizeForNodeAtindexPath unable to get nodes? #146

Open garrettmoon opened 7 years ago

garrettmoon commented 7 years ago

From @ArEnSc on September 24, 2016 19:16

AsyncDisplayKit (1.9.90) Am I missing something here ? thanks

 func collectionView(collectionView: ASCollectionView, constrainedSizeForNodeAtIndexPath indexPath: NSIndexPath) -> ASSizeRange {
        let cellNode:ASCellNode = collectionNode!.view.nodeForItemAtIndexPath(indexPath)! // This returns nothing 
       let size = cellNode.frame.size
      return ASSizeRangeMake(size, size)
      //return ASSizeRangeMake(CGSize.init(width: 0,height: 0), CGSize.init(width: CGFloat.min,height: CGFloat.max))
    }

Copied from original issue: facebookarchive/AsyncDisplayKit#2293

garrettmoon commented 7 years ago

@ArEnSc the cells aren't created yet when this method is called, ASDK needs the results of this method to create the cell. If you want the cells to size automatically with no constraints, you should be able to return ASSizeRangeMake(CGSizeZero, CGSizeMake(CGFLOAT_MAX, CGFLOAT_MAX)).

You may not even need to implement this method, as the default behavior may be what you desire :)

garrettmoon commented 7 years ago

From @ArEnSc on September 26, 2016 22:19

@garrettmoon The issue is I have a ASCollectionNodeX that is nested in a ASCellNodeY and I need to resize the ASCellNode to what the ASCollectionNodeX and its children are how would I attempt to do that? There doesn't seem to be an easy way.

garrettmoon commented 7 years ago

From @hannahmbanana on January 13, 2017 4:8

@ArEnSc - I believe right now, the collection nodes have no way to report their own size. The current work around is write a method that queries each of your cells (ASCellNodeY) and call layoutThatFits: on each of them with the same constrainedSize that the collection would. You can do this loop on a background thread. If the same cell nodes are provided to the collection, then the layout will be cached and not need to recompute. Based on the size of the cell nodes, you can set the .style.preferredSize of the inner collection node and call -setNeedsLayout on it's parent.

We should probably modify one of our example to do this. Any volunteers?

garrettmoon commented 7 years ago

From @hannahmbanana on January 13, 2017 4:10

This framework improvement / feature request is duplicated by #954.

TODO(Hannah): Close once documentation is produced for the current workaround.