Hi, I'm building an app using Compose and some of ...
# compose
z
Hi, I'm building an app using Compose and some of my Composable elements have a default height (similarly to the Compose Material Buttons). I'm wondering how to create the public API of my composable: 1. Have a
Modifier
argument and then add
.height()
internally. The negative side is that there won't be a way to change the composable's height.
Copy code
@Composable
fun MyComposable(
    modifier: Modifier = Modifier
) {
    Surface(modifier = modifier.height(24.dp)
}
2. Have a default value of the
modifier
argument that specifies the height. The downside is that if you want to pass a modifier to the composable, you'd have to add the
height
one as well:
Copy code
@Composable
fun MyComposable(
    modifier: Modifier = Modifier.height(24.dp)
) {
    Surface(modifier = modifier
}
In my particular case the composable will always be displayed in the default height, but I'm asking what's the generally preferred way to do this for composables that may vary in size, but we still want to have some default/min height
o
Number 1 with
Modifier.defaultMinSize()
instead of
Modifier.height()
z
Ah yes, I completely forgot about this modifier! Thanks 🙏
a
You can change the size externally when using pattern 1. See this thread.
👍 1
z
This thread was quite useful! Thanks a lot