Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Jetpack Compose: What's the difference between Modifier.heightIn(...) vs Modifier.preferredHeight(...)

What's the difference between Modifier.heightIn(...) and Modifier.preferredHeight()? They seem to work the same way in my trials.. Does anyone know when to use what and in what scenarios?

like image 410
Archie G. Quiñones Avatar asked Oct 23 '25 15:10

Archie G. Quiñones


1 Answers

Modifier.preferredHeight() sets the height which can be overridden by constraints, instead of Modifier.height, that sets the height regardless of the incoming constraints.

Modifier.heightIn() forces the content to comply with these constraints and centers it in the case that the content is larger than maximum or smaller than minimum.

On a side note, these two functions serve different purposes since the first one takes one argument, and the second takes two. Because of that, they would hardly do the same thing.

Notice there are other functions for width and height, as well as "size", which includes both of them. By looking in the source code (Ctrl + click | Cmd + click), it's possible to see all possibilities and documentation explaining the functionality.

like image 71
Vitor Ramos Avatar answered Oct 27 '25 04:10

Vitor Ramos



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!