Correctly calculate intrinsicContentSize
before first layout run
#215
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This pull requests adds the ability to calculate the
intrinsicContentSize
ofTagListView
without requiring a full layout-run. This is for example the case if some one wants to pre-calculate the sizes ofUICollectionViewCell
s (withsystemLayoutSizeFitting (...)
) that have aTagListView
embedded.In my case, the
intrinsicContentSize
was always wrong (height: number of tag x tag-height) because the tag list inside my static prototyping cell (which is used for size-pre-calculation) was not layouted yet. And since layouting the whole cell is more expensive then usingsystemLayoutSizeFitting()
while gathering the correct cell sizes is critical for scrolling performance of the whole collection view, I had to find a way to calculate theintrinsicContentSize
without that dependency from the view's frame.BTW: Even Apples documentation for
intrinsicContentSize
says:My solution is inspired from
UILabel
'spreferredMaxLayoutWidth
, since multiline labels have the same requirement to calculate their height depending of their width, which they don't know prior layouting.So in
rearrangeViews()
theTagListView
uses the newly introducedpreferredLayoutWidth
property (if set to a proper value) for calculating the distribution of all tags (instead offrame.width
).The getter of
intrinsicContentSize
then looks for the widestrowView
to determine the tag list view's intrinsic width.When using autolayout, the tag list view will then be sized based on it's
intrinsicContentSize
.