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?

More than 3 years have passed since last update.

[Kotlin]JetpackComposeでボタンを押したときのエフェクトについて(リップルエフェクト)

Posted at

概要

ボタンを押したときのエフェクトがコードの書き方によってどう変わるかを比較してみました

本文

JetpackCompose用テンプレートのコードにclickableなBoxを追加したものです。画面をタップするとリップルエフェクトが発生します。

        setContent {
            ComposeClickableTestTheme {
                Surface() {
                    Box(
                        modifier = Modifier
                            .fillMaxSize()
                            .clickable(
                                onClick = { },
                            )
                    ) {
                    }
                }
            }
        }

適用されていたThemeを消しました。clickableなBoxはリップルエフェクトを出さず単純な点滅になります。

        setContent {
            Surface() {
                Box(
                    modifier = Modifier
                        .fillMaxSize()
                        .clickable(
                            onClick = { },
                        )
                ) {
                }
            }
        }

Themeが無いままでも以下のように書き換えると、clickableなBoxはリップルエフェクトを発生するようになります。

        setContent {
            Surface() {
                Box(
                    modifier = Modifier
                        .fillMaxSize()
                        .clickable(
                            onClick = { },
                            interactionSource = remember { MutableInteractionSource() },
                            indication = rememberRipple(bounded = true),
                        ),
                ) {
                }
            }
        }
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?