-
-
Save bicho19/592218bcf2ad6b457202c4530d0ef465 to your computer and use it in GitHub Desktop.
Dashed divider in Jetpack Compose
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
| @Preview | |
| @Composable | |
| private fun DashedDividerPreview() { | |
| DashedDivider( | |
| color = Color.Black, | |
| thickness = 1.dp, | |
| modifier = Modifier | |
| .fillMaxWidth() | |
| .padding(16.dp) | |
| ) | |
| } | |
| @Composable | |
| fun DashedDivider( | |
| thickness: Dp, | |
| color: Color = MaterialTheme.colorScheme.onSurfaceVariant, | |
| phase: Float = 10f, | |
| intervals: FloatArray = floatArrayOf(10f, 10f), | |
| modifier: Modifier | |
| ) { | |
| Canvas( | |
| modifier = modifier | |
| ) { | |
| val dividerHeight = thickness.toPx() | |
| drawRoundRect( | |
| color = color, | |
| style = Stroke( | |
| width = dividerHeight, | |
| pathEffect = PathEffect.dashPathEffect( | |
| intervals = intervals, | |
| phase = phase | |
| ) | |
| ) | |
| ) | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment