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

Sepideh Vatankhah

02/09/2022, 2:40 PM
#compose Hey guys, if we have a compose component which gets two or more modifier, how should we handle it ? I mean the naming of modifiers while lint complains changing the name of modifier parameter
s

Stylianos Gakis

02/09/2022, 3:01 PM
Why does it take two modifiers in the first place?
1
c

Chris Sinco [G]

02/09/2022, 7:23 PM
Yes, if you are taking two of them as parameters to apply to a single element you should just chain them and pass one. If you are taking two to use on different elements it seems those different elements should be different composables.
s

Sepideh Vatankhah

02/09/2022, 9:50 PM
Thanks guys for your answers Here is the stackOverFlow’s link There I asked my question with sample code so you can have better view to understand what I mean exactly. Thanks in advance for your help
c

Chris Sinco [G]

02/09/2022, 11:07 PM
So in your specific snippet with ConstraintLayout, I don’t think you need to pass
layoutId
modifiers down to the Composables because unless you are using them to reference for setting constraints, I don’t think they are being used at all in CompletionSection. How are you using those? That modifier is useful for custom layouts or with saving them in a variable to reference for creating constraints in ConstraintLayout.
My point is based on your snippet, it doesn’t seem those modifiers are being used in a meaningful way in the CompletionSection composable, so you could just pass the strings (“completedIcon”, “newTextField”) as string parameters instead, and then declare the
layoutId
modifier in the CompletionSection function
s

Sepideh Vatankhah

02/10/2022, 8:59 AM
They are working @Chris Sinco [G] well It is a complicated component which becomes very long method so I used decoupled constraintset approach and to avoid making function so long related part became separated functions
s

Stylianos Gakis

02/10/2022, 9:07 AM
I’d still say that you either want those modifiers for the child components to be driven from normal input parameters provided to the function or can use some sort of slot API for those items. I’d love to see the code where you call
CompletionSection
to get a better understanding of what kind of situation you can find yourself into to not be able to shape the API that way.
1
4 Views