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

Shivam Verma

11/03/2023, 5:54 AM
Hey everyone 👋 When creating my own wrapper for a Button (within a design system), I would like to expose the Modifier so that the user can set test tags, set accessibility label etc.
Copy code
CustomButton(
    text: String, 
    onClick: () -> Unit,
    modifier: Modifier
)
However, when setting the accessibility label, user needs to use
Modifier.clickable(..)
which then conflicts with the
onClick
parameter. How would you design the api in this case?
c

curioustechizen

11/03/2023, 6:54 AM
If there is a small number of parameters that you want the user to set, then you could expose them as nullable strings for example. Then your CustomButton implementation can set the appropriate modifiers internally. That said, the compose API guidelines state that every component should expose a modifier parameter anyway.
s

Shivam Verma

11/03/2023, 7:03 AM
That said, the compose API guidelines state that every component should expose a modifier parameter anyway.
Yeah, this also seems to be a good long term solution so as to not end up in the rabbit hole of updating the api whenever a new modifier needs to be set. However, in that case, it seems the solution would be to not have
onClick
as a parameter at all and force the consumers to always use
Modifier.clickable()
.
2 Views