https://kotlinlang.org logo
Title
r

RayeW47

06/08/2022, 7:51 PM
Anybody have any tips for converting a
class
to a
@Composable fun
? I can't quite conceptualize it and for the most part I'm writing imperative UI with compose
a

Adam Powell

06/08/2022, 7:52 PM
got an example?
r

RayeW47

06/08/2022, 7:56 PM
Validating text fields comes to my mind first, because I'm doing that right now. I use a
class
to handle most of the validation logic and I can't figure out how to convert a
class
to a
composable
. More generally, I often find myself writing a class to "separate concerns" rather than doing it the "proper" compose way.
https://kotlinlang.slack.com/archives/CJLTWPH7S/p1654632182706579 This is a small example of how I am handling validation right now and I'm sure there is a way to do it without using
class
but I can't imagine it because I am stuck doing things the old way
a

Adam Powell

06/08/2022, 7:58 PM
maybe think of it less as converting a class to a composable as extracting the state management from the presentation
it's totally fine - even encouraged - to keep policy and state management in objects that then get passed to composables for presentation
r

RayeW47

06/08/2022, 8:02 PM
Hmm, that makes perfect sense. I guess I will just need to start thinking about how to write it out a bit more, then. Thank you!
👍 1
f

Francesc

06/08/2022, 8:21 PM
this seems like the kind of thing a StateHolder would be a good fit for