Mobile Develop/Android

Android Compose 리플 효과 없는 clickable

nyangzzi 2024. 2. 1. 17:41
반응형

 

Modifier 확장함수 생성

fun Modifier.noRippleClickable(onClick: () -> Unit): Modifier = composed {
    clickable(indication = null,
        interactionSource = remember {
            MutableInteractionSource()
        }) {
        onClick()
    }
}

 

 

기존 Modifier.clickable 대신 이용 가능하다

Box(
    modifier = Modifier         
                .noRippleClickable {
                    //todo
                })

 


 

예제 코드

Row(horizontalArrangement = Arrangement.spacedBy(16.dp)){
    Box(modifier = Modifier.size(100.dp).background(Color.Red).noRippleClickable {  })
    Box(modifier = Modifier.size(100.dp).background(Color.Green).clickable {  })
}

 

 

 


 

참고

 

How to disable ripple effect when clicking in Jetpack Compose

In Jetpack Compose, when you enable clickable {} on a modifier for a composable, by default it enables ripple effect for it. How to disable this behavior? Example code Row(modifier = Modifier ...

stackoverflow.com

 

반응형