is there way to make constructor composable? I wan...
# compose
i
is there way to make constructor composable? I want pass through it data that calculates with composable function. It will always call in composable context. Can i do it somehow?
i
You can create a separate method which would return your result
👆 4
👆🏼 1
a
Yep. If you declare a top-level factory function as
Copy code
@Composable
fun ButtonStyle(...) = ButtonStyle(...)
then you get the same call site characteristics and user expectations as a constructor, plus you're forced to keep a "real" constructor public, which ensures that you can create these objects outside of composition, aiding both aggregation as part of other state objects and testability
👍 1
j
private constructor plus operator fun invoke in companion object can “simulate” invoking the constructor
👍 1
a
Indeed, but then you have a private constructor and a type that can only be created during composition. 🙂
👍 2