“Composed” Modifier vs “Standard” Modifier
Jan 21, 2024

- Standard Modifier
- for stateless modifiers
@Stable
fun Modifier.padding(all: Dp) =
this.then(
PaddingModifier(
start = all,
top = all,
end = all,
bottom = all,
rtlAware = true,
inspectorInfo = debugInspectorInfo {
name = "padding"
value = all
}
)
)
- Composed Modifier
- for stateful modifiers
fun Modifier.clickable(
interactionSource: MutableInteractionSource,
indication: Indication?,
enabled: Boolean = true,
onClickLabel: String? = null,
role: Role? = null,
onClick: () -> Unit
) = composed(
factory = {
val onClickState = rememberUpdatedState(onClick)
val pressedInteraction = remember { mutableStateOf<PressInteraction.Press?>(null) }
if (enabled) { ... }
val isRootInScrollableContainer = isComposeRootInScrollableContainer()
val isClickableInScrollableContainer = remember { mutableStateOf(true) }
val delayPressInteraction = rememberUpdatedState { ... }
val gesture = Modifier.pointerInput(interactionSource, enabled) { ... }
Modifier
.then(
remember { ... }
)
.genericClickableWithoutGesture(
gestureModifiers = gesture,
interactionSource = interactionSource,
indication = indication,
enabled = enabled,
onClickLabel = onClickLabel,
role = role,
onLongClickLabel = null,
onLongClick = null,
onClick = onClick
)
},
inspectorInfo = debugInspectorInfo { ... }
)
Share article