Created
January 2, 2023 18:04
-
-
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
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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