SnackBar Direction in Compose

245 Views Asked by At

I implement user interface in Jetpack Compose, and want to show SnackBar inside Compose functions.

the issue is that i can't change SnackBar's Layout Direction to Rtl.

What I've implemented to change the direction:

LaunchedEffect(SnackbarHost(hostState = scaffoldState.snackbarHostState, snackbar = {
    CompositionLocalProvider(LocalLayoutDirection provides LayoutDirection.Rtl) {
        Snackbar(it)
    }
}
)) {

    viewModel.snackBarMessage.collect {
        scaffoldState.snackbarHostState.showSnackbar(
            it,
            null,
            SnackbarDuration.Short
        )
    }
}
1

There are 1 best solutions below

1
saeed ghafari On

you should insert your scaffold in CompositionLocalProvider scope. like this:

 CompositionLocalProvider(LocalLayoutDirection provides LayoutDirection.Rtl) {
     
Scaffold(){
...
}

}