• python
  • javascript
  • reactjs
  • sql
  • c#
  • java
Facebook Twitter Instagram
Devs Fixed
  • python
  • javascript
  • reactjs
  • sql
  • c#
  • java
Devs Fixed
Home ยป Resolved: Change Jetpack Compose view size dinamically

Resolved: Change Jetpack Compose view size dinamically

0
By Isaac Tonny on 16/06/2022 Issue
Share
Facebook Twitter LinkedIn

Question:

I want create a simple button with 3 predefined sizes, I’m adding an enum param on my Compose view and depending on it I’m trying to set one of this predefined sizes as the width and height.
My enum looks like this:
And my custom button:
My Issue is that so far I haven’t been able to set the width or height of the button this way, they always remain as the default.

Answer:

When you call functions on a modifier, those functions don’t mutate the original modifier, instead they return a new (combined) modifier as their result, so you have to save the result from your when expression into a local value and then pass that value as the modifier parameter to the Button composable.
You also have to chain the function calls to .width() and to .height() inside the when expression (inside each case blocks).
With all those changes you would get something like this

If you have better answer, please add a comment about this, thank you!

android android-custom-view android-jetpack android-jetpack-compose kotlin
Share. Facebook Twitter LinkedIn

Related Posts

Resolved: itertools: cycle through several lists N times via iteration

24/03/2023

Resolved: Convert function is not working with {fn } in SQL Server

24/03/2023

Resolved: Why reference in pointer array doesn’t have data?

24/03/2023

Leave A Reply

© 2023 DEVSFIX.COM

Type above and press Enter to search. Press Esc to cancel.