Deprecated Replaced with new overload that only supports IndicationNodeFactory instances inside LocalIndication, and does not use composed
fun Modifier.combinedClickable(
enabled: Boolean = true,
onClickLabel: String? = null,
role: Role? = null,
onLongClickLabel: String? = null,
onLongClick: (() -> Unit)? = null,
onDoubleClick: (() -> Unit)? = null,
hapticFeedbackEnabled: Boolean = true,
onClick: () -> Unit,
) =
composed(
inspectorInfo =
debugInspectorInfo {
name = "combinedClickable"
properties["enabled"] = enabled
properties["onClickLabel"] = onClickLabel
properties["role"] = role
properties["onClick"] = onClick
properties["onDoubleClick"] = onDoubleClick
properties["onLongClick"] = onLongClick
properties["onLongClickLabel"] = onLongClickLabel
properties["hapticFeedbackEnabled"] = hapticFeedbackEnabled
}
) {
val localIndication = LocalIndication.current
val interactionSource =
if (localIndication is IndicationNodeFactory) {
null
} else {
remember { MutableInteractionSource() }
}
Modifier.combinedClickable(
enabled = enabled,
onClickLabel = onClickLabel,
onLongClickLabel = onLongClickLabel,
onLongClick = onLongClick,
onDoubleClick = onDoubleClick,
onClick = onClick,
role = role,
indication = localIndication,
interactionSource = interactionSource,
hapticFeedbackEnabled = hapticFeedbackEnabled,
)
}
Configure component to receive clicks, double clicks and long clicks via input or accessibility "click" event.
Add this modifier to the element to make it clickable within its bounds.
If you need only click handling, and no double or long clicks, consider using clickable
This version has no MutableInteractionSource or Indication parameters, the default indication from LocalIndication will be used. To specify MutableInteractionSource or Indication, use the other overload.
If you are only creating this combinedClickable modifier inside composition, consider using the other overload and explicitly passing LocalIndication.current for improved performance. For more information see the documentation on the other overload.
Note, if the modifier instance gets re-used between a key down and key up events, the ongoing input will be aborted.
Note Any removal operations on Android Views from clickable should wrap onClick in a post { } block to guarantee the event dispatch completes before executing the removal. (You do not need to do this when removing a composable because Compose guarantees it completes via the snapshot state system.)
Parameters
| enabled | Controls the enabled state. When false, onClick, onLongClick or onDoubleClick won't be invoked |
| onClickLabel | semantic / accessibility label for the onClick action |
| role | the type of user interface element. Accessibility services might use this to describe the element or do customizations |
| onLongClickLabel | semantic / accessibility label for the onLongClick action |
| onLongClick | will be called when user long presses on the element |
| onDoubleClick | will be called when user double clicks on the element |
| hapticFeedbackEnabled | whether to use the default HapticFeedback behavior |
| onClick | will be called when user clicks on the element |
fun Modifier.combinedClickable(
enabled: Boolean = true,
onClickLabel: String? = null,
role: Role? = null,
onLongClickLabel: String? = null,
onLongClick: (() -> Unit)? = null,
onDoubleClick: (() -> Unit)? = null,
hapticFeedbackEnabled: Boolean = true,
interactionSource: MutableInteractionSource? = null,
onClick: () -> Unit,
): Modifier
Configure component to receive clicks, double clicks and long clicks via input or accessibility "click" event.
Add this modifier to the element to make it clickable within its bounds.
If you need only click handling, and no double or long clicks, consider using clickable
This overload will use the Indication from LocalIndication. Use the other overload to explicitly provide an Indication instance. Note that this overload only supports IndicationNodeFactory instances provided through LocalIndication - it is strongly recommended to migrate to IndicationNodeFactory, but you can use the other overload if you still need to support Indication instances that are not IndicationNodeFactory.
If interactionSource is null, an internal MutableInteractionSource will be lazily created only when needed. This reduces the performance cost of combinedClickable during composition, as creating the indication can be delayed until there is an incoming androidx.compose.foundation.interaction.Interaction. If you are only passing a remembered MutableInteractionSource and you are never using it outside of combinedClickable, it is recommended to instead provide null to enable lazy creation. If you need the Indication to be created eagerly, provide a remembered MutableInteractionSource.
Note, if the modifier instance gets re-used between a key down and key up events, the ongoing input will be aborted.
Note Any removal operations on Android Views from clickable should wrap onClick in a post { } block to guarantee the event dispatch completes before executing the removal. (You do not need to do this when removing a composable because Compose guarantees it completes via the snapshot state system.)
Parameters
| enabled | Controls the enabled state. When false, onClick, onLongClick or onDoubleClick won't be invoked |
| onClickLabel | semantic / accessibility label for the onClick action |
| role | the type of user interface element. Accessibility services might use this to describe the element or do customizations |
| onLongClickLabel | semantic / accessibility label for the onLongClick action |
| onLongClick | will be called when user long presses on the element |
| onDoubleClick | will be called when user double clicks on the element |
| hapticFeedbackEnabled | whether to use the default HapticFeedback behavior |
| interactionSource | MutableInteractionSource that will be used to dispatch PressInteraction.Press when this clickable is pressed. If null, an internal MutableInteractionSource will be created if needed. |
| onClick | will be called when user clicks on the element |
Deprecated Maintained for binary compatibility
fun Modifier.combinedClickable(
enabled: Boolean = true,
onClickLabel: String? = null,
role: Role? = null,
onLongClickLabel: String? = null,
onLongClick: (() -> Unit)? = null,
onDoubleClick: (() -> Unit)? = null,
onClick: () -> Unit,
) =
composed(
inspectorInfo =
debugInspectorInfo {
name = "combinedClickable"
properties["enabled"] = enabled
properties["onClickLabel"] = onClickLabel
properties["role"] = role
properties["onClick"] = onClick
properties["onDoubleClick"] = onDoubleClick
properties["onLongClick"] = onLongClick
properties["onLongClickLabel"] = onLongClickLabel
}
) {
val localIndication = LocalIndication.current
val interactionSource =
if (localIndication is IndicationNodeFactory) {
null
} else {
remember { MutableInteractionSource() }
}
Modifier.combinedClickable(
enabled = enabled,
onClickLabel = onClickLabel,
onLongClickLabel = onLongClickLabel,
onLongClick = onLongClick,
onDoubleClick = onDoubleClick,
onClick = onClick,
role = role,
indication = localIndication,
interactionSource = interactionSource,
hapticFeedbackEnabled = true,
)
}
fun Modifier.combinedClickable(
interactionSource: MutableInteractionSource?,
indication: Indication?,
enabled: Boolean = true,
onClickLabel: String? = null,
role: Role? = null,
onLongClickLabel: String? = null,
onLongClick: (() -> Unit)? = null,
onDoubleClick: (() -> Unit)? = null,
hapticFeedbackEnabled: Boolean = true,
onClick: () -> Unit,
) =
clickableWithIndicationIfNeeded(
interactionSource = interactionSource,
indication = indication,
) { intSource, indicationNodeFactory ->
CombinedClickableElement(
interactionSource = intSource,
indicationNodeFactory = indicationNodeFactory,
useLocalIndication = false,
enabled = enabled,
onClickLabel = onClickLabel,
role = role,
onClick = onClick,
onLongClickLabel = onLongClickLabel,
onLongClick = onLongClick,
onDoubleClick = onDoubleClick,
hapticFeedbackEnabled = hapticFeedbackEnabled,
)
}
Configure component to receive clicks, double clicks and long clicks via input or accessibility "click" event.
Add this modifier to the element to make it clickable within its bounds.
If you need only click handling, and no double or long clicks, consider using clickable.
Add this modifier to the element to make it clickable within its bounds.
If interactionSource is null, and indication is an IndicationNodeFactory, an internal MutableInteractionSource will be lazily created along with the indication only when needed. This reduces the performance cost of clickable during composition, as creating the indication can be delayed until there is an incoming androidx.compose.foundation.interaction.Interaction. If you are only passing a remembered MutableInteractionSource and you are never using it outside of clickable, it is recommended to instead provide null to enable lazy creation. If you need indication to be created eagerly, provide a remembered MutableInteractionSource.
If indication is not an IndicationNodeFactory, and instead implements the deprecated Indication.rememberUpdatedInstance method, you should explicitly pass a remembered MutableInteractionSource as a parameter for interactionSource instead of null, as this cannot be lazily created inside clickable.
Note, if the modifier instance gets re-used between a key down and key up events, the ongoing input will be aborted.
Note Any removal operations on Android Views from clickable should wrap onClick in a post { } block to guarantee the event dispatch completes before executing the removal. (You do not need to do this when removing a composable because Compose guarantees it completes via the snapshot state system.)
Parameters
| interactionSource | MutableInteractionSource that will be used to emit PressInteraction.Press when this clickable is pressed. If null, an internal MutableInteractionSource will be created if needed. |
| indication | indication to be shown when modified element is pressed. By default, indication from LocalIndication will be used. Pass null to show no indication, or current value from LocalIndication to show theme default |
| enabled | Controls the enabled state. When false, onClick, onLongClick or onDoubleClick won't be invoked |
| onClickLabel | semantic / accessibility label for the onClick action |
| role | the type of user interface element. Accessibility services might use this to describe the element or do customizations |
| onLongClickLabel | semantic / accessibility label for the onLongClick action |
| onLongClick | will be called when user long presses on the element |
| onDoubleClick | will be called when user double clicks on the element |
| hapticFeedbackEnabled | whether to use the default HapticFeedback behavior |
| onClick | will be called when user clicks on the element |
Deprecated Maintained for binary compatibility
fun Modifier.combinedClickable(
interactionSource: MutableInteractionSource?,
indication: Indication?,
enabled: Boolean = true,
onClickLabel: String? = null,
role: Role? = null,
onLongClickLabel: String? = null,
onLongClick: (() -> Unit)? = null,
onDoubleClick: (() -> Unit)? = null,
onClick: () -> Unit,
) =
clickableWithIndicationIfNeeded(
interactionSource = interactionSource,
indication = indication,
) { intSource, indicationNodeFactory ->
CombinedClickableElement(
interactionSource = intSource,
indicationNodeFactory = indicationNodeFactory,
useLocalIndication = false,
enabled = enabled,
onClickLabel = onClickLabel,
role = role,
onClick = onClick,
onLongClickLabel = onLongClickLabel,
onLongClick = onLongClick,
onDoubleClick = onDoubleClick,
hapticFeedbackEnabled = true,
)
}
Code Examples
ClickableSample
@Composable
fun ClickableSample() {
val count = remember { mutableStateOf(0) }
// content that you want to make clickable
Text(text = count.value.toString(), modifier = Modifier.clickable { count.value += 1 })
}