Hi , I'm trying to build a custom snackbar , I'm c...
# compose
w
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.
Copy code
@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
Why not create your own
SnackbarHost
?
w
Do you have any references , or you wanted to suggest to take a look at the source code?
a
Aren't you already looking at the source code?
w
Yes I'm already doing that. Just asking to check if you already aware of any sample
a
What kind of example do you want? You just need to copy ~30 lines of code.
w
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
So you are actually asking how to build the animation. You can check
FadeInFadeOutWithScale
or
Crossfade
.
w
Okay .