Retrieving the content size that caused overflow #1807
Reference in New Issue
Block a user
No description provided.
Delete Branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Hi, since Yoga lets us know when overflow occurs, I assume it might also know the content size. If that's the case, could an API be added to access this information? This would save users from having to iterate and recalculate it manually.
Hi. I also hit the same issue as you described while implementing scroll view. Unfortunately there are issues from 2017 asking the same API and Yoga team didn't implemented the requested feature. For now we can solve this by two approach. One is add intermediate node between scroll view and its content, then you can get width/height of intermediate node which will be the natural size of content. Second solution is iterating children and manually calculating bounding box and caching it, and invalidating the cache on YGNodeSetDirtiedFunc().
Here is the basic implementation for second solution.
Hi @elgunhuseynli, thank you! I eventually ended up calculating it myself as you suggested, but ignoring nodes with absolute pos. In my case, it's for window resizing, where I want to avoid letting the user resize it to less than the minimum content size.
So, after layout, I manually calculate the content bounds (which luckily are never more than 2 or 3 nodes) and check at the same time if there is overflow with the parent. If there is, I update the parent size and calculate again. I always check if there is overflow myself because I noticed that the
hasOverflow
result applies only to one of the axes, I assume the layout direction, if the other axis has overflow it still returns false.Closing as this appears to be a duplicate of https://github.com/facebook/yoga/issues/623