# compose

Marco Pierucci

10/18/2023, 6:23 PM
👋 Getting some doubts regarding the slot api pattern and enabled state 🧵
So I have the following snippet for a check box item
Copy code
fun CheckBoxItem(
    modifier: Modifier = Modifier,
    checked: Boolean,
    label: String,
    onCheckedChange: (Boolean) -> Unit,
    enabled: Boolean = true,
    trailIcon: @Composable (RowScope.() -> Unit)? = null,
) {
        modifier = modifier
                value = checked,
                onValueChange = onCheckedChange,
                role = Role.Checkbox,
   enabled = enabled
        verticalAlignment = Alignment.CenterVertically,
    ) {
            modifier = Modifier.weight(1f),
            text = label,
            style = MaterialTheme.typography.bodyLarge,
            checked = checked,
            onCheckedChange = null,
            enabled = enabled
        if (trailIcon != null) trailIcon()
I went for the slot approach to allow callers of this funciton to better define the trailing icons they want to set. However this means now that the enabled parameter will not take effect on that slow ( leaving the responibility ont eh caller which seems annoying). Should I wrap the trailing icon lamba in another row and play with the gestures or is the slot pattern not the way to go here?
I guess since they have to pass the is enabled param anyways they can use it when defining the lambda as well 🤷


10/18/2023, 6:32 PM
Maybe use a interface event and pass that onto here and call it when checked

Marco Pierucci

10/18/2023, 6:34 PM
teh icon slot is independent of the checked change interaction. And that being said maybe thats the anwser, they should not be composed under the same composable