0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

【Jetpack Compose】タップ位置と違う場所にRipple Effect(Indication)を適用する

Last updated at Posted at 2025-09-22

以下のようにタイトル・画像は両方タップできるけど、Rippleは画像のみに適用したい、とします

CleanShot 2025-09-22 at 10.20.48.gif

実装

interactionSourceをタップ対象のコンポーネントの親に定義し、それらを共有すると実現できます。

@Composable
internal fun IndicationExample(
  modifier: Modifier = Modifier,
) {
+ val interactionSource = remember { MutableInteractionSource() }
  var selected by remember { mutableStateOf(false) }

  Column(
    horizontalAlignment = Alignment.CenterHorizontally,
    verticalArrangement = Arrangement.spacedBy(4.dp),
    modifier = modifier
      .clickable(
        onClick = { selected = !selected },
+       indication = null,
+       interactionSource = interactionSource,
      )
  ) {
    Box(
      contentAlignment = Alignment.Center,
      modifier = Modifier
          .clip(RoundedCornerShape(4.dp))
          .background(Color.LightGray)
+         .indication(indication = LocalIndication.current, interactionSource = interactionSource)
          .size(96.dp)
          .border(
              width = 2.dp,
              color = if (selected) MaterialTheme.colorScheme.primary else Color.Transparent,
              shape = RoundedCornerShape(4.dp),
          ),
    ) {
      Text("画像")
    }
    Text(
      text = "タイトル",
      textAlign = TextAlign.Center,
    )
  }
}
0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?