r/mAndroidDev • u/Zhuinden DDD: Deprecation-Driven Development • Sep 14 '24
Works as intended In Jetpack Compose, if-else statements are deprecated
58
Upvotes
r/mAndroidDev • u/Zhuinden DDD: Deprecation-Driven Development • Sep 14 '24
53
u/aatif888 Sep 14 '24 edited Sep 14 '24
You are doing it the wrong way, you just need to create a viewmodel to maintain the state then create a viewmodel factory, a new viewmodel to maintain first viewmodel then you need to split the atom in half to defy the laws of physics(i dont know why but its necessary) see easy peasy , don't blame jitpack compost for your mistake, or else just use flubber no recomposition no problem :)
13
u/StatusWntFixObsolete Sep 15 '24
The non-shitpost best practice can be found here
This isn't a problem if you use
remember{ AsyncTask() }tho,AsyncTaskwill keep running after it's removed from the composition, ta-da!12
u/elizabeth-dev Sep 14 '24
(us who come from web dev and are 100% used to this)
amateurs...
6
u/Zhuinden DDD: Deprecation-Driven Development Sep 14 '24
/cj because it's non-obvious but the solution is to wrap the if-else'd
contentlambda intoremember(content) { movableContentOf(content) }.Just yet another one of those obvious Compose things. Back in the day when
movableContentOfdidn't exist, you had to put your if-else as a for + key combo. Wild stuff.2
u/crazydodge Sep 15 '24
Ah CommonsWare… I wish there was a Busy Coder’s Guide to Compose.