https://kotlinlang.org logo
#compose
Title
# compose
m

Masoud Kardani

03/07/2023, 2:14 PM
Hi guys, is there any way to create a Builder pattern in compose (like what we have for the Modifier) that we can build our view by a builder and render it at last?
I don't want to use Slot since my base layout can be vary depends on use cases and blocks
z

Zach Klippenstein (he/him) [MOD]

03/07/2023, 5:01 PM
Sure, nothing special about doing this. Just make your builder then call a composable with the builder result
m

Masoud Kardani

03/07/2023, 5:05 PM
But as I know compose draw layout immediately so if i create a builder it doesn't wait to build as once, am I right? Do you have a simple example? 🙏
z

Zach Klippenstein (he/him) [MOD]

03/07/2023, 5:07 PM
Well you haven’t given a lot of info about how you want to use the builder. If you just want to use a builder to construct some configuration for a view, you can just use your builder from a parent composable.
If you can share an example of the code you want to be able to write, I can be more specific
6 Views