Image generated by Midjourney, prompt: Tower of glass and steel reaching into the sky

Reach out to infinity

Vladimir Raupov

--

Jetpack Compose provides a set of components which only compose and lay out items which are visible in the component’s viewport. These components include LazyColumn and LazyRow.

LazyColumn is a great tool for constructing screens of various complexities. However, some developers think that anything can be added to this column and LazyColumn will obediently draw each item, yet there is one issue.

Are you familiar with this error?

java.lang.IllegalStateException: Vertically scrollable component was measured with an infinity maximum height constraints, which is disallowed.

This error happens because a vertically scrollable component needs to know the maximum height it can occupy in the layout in order to correctly measure and display its content. If the maximum height constraint is set to infinity, the component cannot determine its size and therefore cannot be properly measured.

Yes, that’s what you thought. Placing one LazyColumn inside another or adding a scrollable Column to the LazyColumn can lead to a potentially infinite height, which is difficult to measure.

FiberglassColumn

Not long ago, I released Fiberglass, a tool for building complex screens from simple blocks. Unfortunately, I made one mistake. I made FiberglassColumn and FiberglassRow scrollable by default. One of the first users encountered an issue: an infinite height error.

It turned out that the user had placed a FiberglassColumn inside a FiberglassLazyColumn. It was a great idea that I hadn’t foreseen, so I released a fix. Now, FiberglassColumn and FiberglassRow are no longer scrollable without explicitly setting the scroll state.

Conclusion

The user is happy with the fix, and I learned my lesson. Maximum functionality by default is not always a good idea.

By the way, the problem won’t appear if you explicitly limit the height of the nested list using a modifier, but it’s hard to guess without experience.

Well, that’s all for today. Write good code and have fun! Bye!

--

--