Blog Infos
Author
Published
Topics
Published

Photo by Ave Calvar on Unsplash

 

When working with some widgets in Compose, we get the ripple effect out of the box. While this is a nice visual effect to have, sometimes it just doesn’t work well with the design in mind, so we have to find a way to get rid of it.

I was facing this same dilemma when designing a toggleable widget layout recently, but after some tinkering, I was able to get rid of it, and it’s as simple as using a Kotlin extension function.

Toggleable…
fun Modifier.noRippleToggleable(
    value: Boolean,
    onValueChange: (Boolean) -> Unit
): Modifier = composed {
    toggleable(
        value = value,
        indication = null,
        interactionSource = remember { MutableInteractionSource() },
        onValueChange = onValueChange
    )
}

What I did was simple extend the compose modifier public interface and call the base toggleable modifier but with little adjustment to the indication parameter we change the value to null, that all and we apply it like this

Column(
    modifier =
    Modifier
        .wrapContentSize()
        .noRippleToggleable(
            value = isSelected,
        ) {
            //onValuChangeImplementation
        },
    verticalArrangement = Arrangement.Center,
    horizontalAlignment = Alignment.CenterHorizontally
) {
//your composable here
}
Clickable…
inline fun Modifier.noRippleClickable(
    crossinline onClick: () -> Unit
): Modifier = composed {
    clickable(
        indication = null,
        interactionSource = remember { MutableInteractionSource() }) {
        onClick()
    }
}

Just like we did with the Toggleable modifier above, we just need to give the indication parameter null value, and it is applied below

Column(
    modifier =
    Modifier
        .wrapContentSize()
        .noRippleClickable(
          onClick()
        ) {
            //onValuChangeImplementation
        },
    verticalArrangement = Arrangement.Center,
    horizontalAlignment = Alignment.CenterHorizontally
) {
//your composable here
}

Thanks for joining me on this journey. I hope you found this information useful and informative. If there’s anything you’re curious about or if I missed anything important, please don’t hesitate to reach out and ask!

I’m here to help, and I promise to respond to every comment. Let’s keep the conversation going!

Until next time, I’m Jnr. Bye for now! 🖤

This article was originally published on proandroiddev.com

Job Offers

Job Offers

There are currently no vacancies.

OUR VIDEO RECOMMENDATION

, ,

Migrating to Jetpack Compose – an interop love story

Most of you are familiar with Jetpack Compose and its benefits. If you’re able to start anew and create a Compose-only app, you’re on the right track. But this talk might not be for you…
Watch Video

Migrating to Jetpack Compose - an interop love story

Simona Milanovic
Android DevRel Engineer for Jetpack Compose
Google

Migrating to Jetpack Compose - an interop love story

Simona Milanovic
Android DevRel Engin ...
Google

Migrating to Jetpack Compose - an interop love story

Simona Milanovic
Android DevRel Engineer f ...
Google

Jobs

YOU MAY BE INTERESTED IN

YOU MAY BE INTERESTED IN

blog
It’s one of the common UX across apps to provide swipe to dismiss so…
READ MORE
blog
In this part of our series on introducing Jetpack Compose into an existing project,…
READ MORE
blog
In the world of Jetpack Compose, where designing reusable and customizable UI components is…
READ MORE
blog

How to animate BottomSheet content using Jetpack Compose

Early this year I started a new pet project for listening to random radio…
READ MORE

Leave a Reply

Your email address will not be published. Required fields are marked *

Fill out this field
Fill out this field
Please enter a valid email address.

Menu