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

alorma

11/09/2020, 11:27 AM
Hi Guys! I want to ask what is the best way to do something... I want to create a Composable ("view") to do a TimeLine (for example), and this will contains an icon, color and content for each "row" But, what I'm not sure is... if each row has a title, what's the best way? make a composable function with lambda that returns a String? What about icon? A lambda that returns an Asset? Or instead, a composable lambda to allow user to customize the title / icon... so it will allow change the size of the icon etc... TL;DR: What I'm not sure in compose is... how I allow customization of content with some constrained rules about style / size etc...
If i allow a lambda to build in a lambda the tittle of a row, how can i Make that all titles have the same color? or same alignement...
Not sure if I explained well..
s

subashz

11/09/2020, 11:31 AM
you can refer this video if you want a time line view.

https://www.youtube.com/watch?v=j6ETh_oTv3U

. Don't know if that's what you meant by
a

alorma

11/09/2020, 11:32 AM
well, my question is more about... how allow custom composable with constraining styles / sizes...
s

subashz

11/09/2020, 11:57 AM
So, you mean right way user can customize your Composable custom views which are distributed as a library.
a

alorma

11/09/2020, 12:22 PM
yes
how they can add content in my composable views, weith some "library" styling
i let them add content, but i want to control how that content is styled for example
https://github.com/alorma/Compose-Debug-Drawer here I let theme add content on each module.... but how can I be sure content follows some design rules
z

Zach Klippenstein (he/him) [MOD]

11/09/2020, 2:41 PM
Generally the most idiomatic and flexible way to accept custom child content is to accept a “slot” (a composable function). Since your composable is in full control of calling those functions, you can place whatever size constraints you wish on it, and wrap it with whatever theming ambients you wish (eg content color or text style).
4
v

Vinay Gaba

11/09/2020, 4:46 PM
This blog does a good job in talking about what Zach is referring to - https://epicreact.dev/one-react-mistake-thats-slowing-you-down. Even though its using React as an example, the same principles apply.
1
🔝 1