https://kotlinlang.org logo
Title
w

wintersoldier

02/06/2023, 9:01 AM
Hi , I'm trying to build a custom snackbar , I'm currently using
SnackbarHost
, the issue is basically while displaying snackbar appears with default fade-in fade out animation where I want a different animation.
Checked Snackbar composable , and I have seen
FadeInFadeOutWithScale
composable is used . Is there some workaround to change it.
@Composable
fun SnackbarHost(
    hostState: SnackbarHostState,
    modifier: Modifier = Modifier,
    snackbar: @Composable (SnackbarData) -> Unit = { Snackbar(it) }
) {
    val currentSnackbarData = hostState.currentSnackbarData
    val accessibilityManager = LocalAccessibilityManager.current
    LaunchedEffect(currentSnackbarData) {
        if (currentSnackbarData != null) {
            val duration = currentSnackbarData.duration.toMillis(
                currentSnackbarData.actionLabel != null,
                accessibilityManager
            )
            delay(duration)
            currentSnackbarData.dismiss()
        }
    }
    FadeInFadeOutWithScale(
        current = hostState.currentSnackbarData,
        modifier = modifier,
        content = snackbar
    )
}
a

Albert Chang

02/06/2023, 10:07 AM
Why not create your own
SnackbarHost
?
w

wintersoldier

02/06/2023, 10:09 AM
Do you have any references , or you wanted to suggest to take a look at the source code?
a

Albert Chang

02/06/2023, 10:09 AM
Aren't you already looking at the source code?
w

wintersoldier

02/06/2023, 10:10 AM
Yes I'm already doing that. Just asking to check if you already aware of any sample
a

Albert Chang

02/06/2023, 10:11 AM
What kind of example do you want? You just need to copy ~30 lines of code.
w

wintersoldier

02/06/2023, 10:13 AM
Basically
FadeInFadeOutWithScale
is the composable which is available gives the fade in fade out effect . Now the example I'm looking at this a composable similar to ``FadeInFadeOutWithScale`` but it does animate towards top to bottom.
a

Albert Chang

02/06/2023, 10:18 AM
So you are actually asking how to build the animation. You can check
FadeInFadeOutWithScale
or
Crossfade
.
w

wintersoldier

02/06/2023, 10:58 AM
Okay .