Skip to content

Instantly share code, notes, and snippets.

@luongvo
Created January 2, 2023 18:04
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save luongvo/f5cc7e679c0388996ea460969fb4335f to your computer and use it in GitHub Desktop.
Save luongvo/f5cc7e679c0388996ea460969fb4335f to your computer and use it in GitHub Desktop.
Jetpack Compose ModalDrawer from right/end side https://issuetracker.google.com/issues/174514369#comment18
import androidx.compose.foundation.layout.ColumnScope
import androidx.compose.material.*
import androidx.compose.runtime.Composable
import androidx.compose.runtime.CompositionLocalProvider
import androidx.compose.ui.Modifier
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.graphics.Shape
import androidx.compose.ui.platform.LocalLayoutDirection
import androidx.compose.ui.unit.Dp
import androidx.compose.ui.unit.LayoutDirection
/**
* ModalDrawer from right/end side
* https://issuetracker.google.com/issues/174514369#comment18
*/
@Composable
fun RtlModalDrawer(
drawerContent: @Composable ColumnScope.() -> Unit,
modifier: Modifier = Modifier,
drawerState: DrawerState = rememberDrawerState(DrawerValue.Closed),
gesturesEnabled: Boolean = true,
drawerShape: Shape = MaterialTheme.shapes.large,
drawerElevation: Dp = DrawerDefaults.Elevation,
drawerBackgroundColor: Color = MaterialTheme.colors.surface,
drawerContentColor: Color = contentColorFor(drawerBackgroundColor),
scrimColor: Color = DrawerDefaults.scrimColor,
content: @Composable () -> Unit
) {
CompositionLocalProvider(LocalLayoutDirection provides LayoutDirection.Rtl) {
ModalDrawer(
modifier = modifier,
drawerState = drawerState,
gesturesEnabled = gesturesEnabled,
drawerShape = drawerShape,
drawerElevation = drawerElevation,
drawerBackgroundColor = drawerBackgroundColor,
drawerContentColor = drawerContentColor,
scrimColor = scrimColor,
drawerContent = {
CompositionLocalProvider(LocalLayoutDirection provides LayoutDirection.Ltr) {
drawerContent()
}
}
) {
CompositionLocalProvider(LocalLayoutDirection provides LayoutDirection.Ltr) {
content()
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment