Can we pass Composable function as a constructor a...
# compose
k
Can we pass Composable function as a constructor argument of a Class ?
I'm using TextFieldState class from JetSurvey and I want
errorFor
function to be Composable so that I can pass string resource ids instead of static strings
a
Mechanically: yes, it will work. We pass composable functions to other composable functions as parameters all the time. Best practice/is it the best answer to this problem: I'd avoid it and instead have your TextFieldState accept an Android
Context
as a constructor dependency, and load your string resources using that. There's no reason to require composition for loading strings.
Or even just have your errorFor function close over a reference to a Context, keeping Context out of this TextFieldState abstraction entirely
k
Will that support locale configuration changes ?
a
yes