Jetpack Compose에서 스낵바를 사용하고 싶다면 아주 간단하다.
@Composable
fun CommonSnackBar(text: String) {
val isShow = remember { mutableStateOf(true) }
if (isShow.value)
Snackbar(modifier = Modifier.padding(horizontal = 8.dp)) {
LaunchedEffect(Unit) {
delay(1500)
isShow.value = false
}
Text(
text = text,
color = Color.White,
fontSize = 12.sp,
textAlign = TextAlign.Center,
)
}
}
Kotlin
복사
SnackBar { } 안에 원하는 Text()를 추가해주고, LaunchedEffect에 delay를 주면 스낵바가 표시된 후 1.5초 후에 닫힌다.