Jetpack Compose 中的 Material3 导航栏出现错误波纹

发布于 2025-01-13 00:14:52 字数 1004 浏览 1 评论 0原文

当我在 Jetpack Compose 中使用 Material3 NavigationBar 时,我得到了错误的矩形波纹效果,如下所示:

在此处输入图像描述

Material3 库版本:1.0.0-alpha06 代码:

NavigationBar(modifier = Modifier.navigationBarsPadding()) {
                NavigationBarItem(
                    selected = ...,
                    onClick = {
                        navController.navigate(ScreenComponents(context).mainScreen) {
                            launchSingleTop = true
                        }
                    },
                    icon = {
                        ...
                    },
                    alwaysShowLabel = false,
                    label = {
                        Text(text = ..., color = MaterialTheme.colorScheme.onSurface)
                    }
                )
                // ...

When I use Material3 NavigationBar in Jetpack Compose I get wrong rectangular ripple effect like this:

enter image description here

Material3 library version: 1.0.0-alpha06
Code:

NavigationBar(modifier = Modifier.navigationBarsPadding()) {
                NavigationBarItem(
                    selected = ...,
                    onClick = {
                        navController.navigate(ScreenComponents(context).mainScreen) {
                            launchSingleTop = true
                        }
                    },
                    icon = {
                        ...
                    },
                    alwaysShowLabel = false,
                    label = {
                        Text(text = ..., color = MaterialTheme.colorScheme.onSurface)
                    }
                )
                // ...

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

永不分离 2025-01-20 00:14:52

这不是一个错误。它遵循材料指南

输入图片此处描述

It is not a bug. It follows the material guidelines.

enter image description here

十年九夏 2025-01-20 00:14:52

自从 @Gabriele Mariotti 的答案以来,他们似乎已经更改了指导图像,现在波纹只出现在“药丸”上。

指南

有一种简单的方法可以完全禁用波纹,但不能将其隔离到药丸上。希望他们在 M3 可组合项退出 alpha 之前更新此内容。

private object NoRippleTheme : RippleTheme {
    @Composable
    override fun defaultColor() = Color.Transparent

    @Composable
    override fun rippleAlpha() = RippleAlpha(0F, 0F, 0F, 0F)
}
CompositionLocalProvider(LocalRippleTheme provides NoRippleTheme) {
        NavigationBar {
            ...

They seem to have changed the guideline images since the answer from @Gabriele Mariotti and now the ripple only appears on the 'pill'.

Guidelines

There is an easy way to disable the ripple entirely, but not to isolate it to the pill. Hopefully they update this before the M3 composables come out of alpha.

private object NoRippleTheme : RippleTheme {
    @Composable
    override fun defaultColor() = Color.Transparent

    @Composable
    override fun rippleAlpha() = RippleAlpha(0F, 0F, 0F, 0F)
}
CompositionLocalProvider(LocalRippleTheme provides NoRippleTheme) {
        NavigationBar {
            ...
焚却相思 2025-01-20 00:14:52

NavigationBarItem 中,我使用此修改器来更改波纹的形状

modifier = Modifier
    .padding(4.dp)
    .background(MaterialTheme.colorScheme.background, RoundedCornerShape(24.dp))
    .clip(RoundedCornerShape(24.dp))

In NavigationBarItem I use this modifier to change the shape of the ripple

modifier = Modifier
    .padding(4.dp)
    .background(MaterialTheme.colorScheme.background, RoundedCornerShape(24.dp))
    .clip(RoundedCornerShape(24.dp))
失退 2025-01-20 00:14:52

我设法通过指定自定义交互源来消除对药丸的连锁反应:

private object NoRippleInteractionSource : MutableInteractionSource {

    override val interactions: Flow<Interaction> = emptyFlow()

    override suspend fun emit(interaction: Interaction) {}

    override fun tryEmit(interaction: Interaction) = true
}

并将此交互源作为参数传递:

NavigationBarItem(
    interactionSource = NoRippleInteractionSource,
    selected = isSelected,
    onClick = onClick,
    ...
)

I managed to remove a ripple effect on the pill by specifying a custom interaction source:

private object NoRippleInteractionSource : MutableInteractionSource {

    override val interactions: Flow<Interaction> = emptyFlow()

    override suspend fun emit(interaction: Interaction) {}

    override fun tryEmit(interaction: Interaction) = true
}

and passing this interaction source as an argument:

NavigationBarItem(
    interactionSource = NoRippleInteractionSource,
    selected = isSelected,
    onClick = onClick,
    ...
)
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文