Skip to content

Instantly share code, notes, and snippets.

@kafri8889
Created June 12, 2022 02:49
Show Gist options
  • Select an option

  • Save kafri8889/463b6c904a54a22e412eb11ad152cf98 to your computer and use it in GitHub Desktop.

Select an option

Save kafri8889/463b6c904a54a22e412eb11ad152cf98 to your computer and use it in GitHub Desktop.

Revisions

  1. kafri8889 created this gist Jun 12, 2022.
    36 changes: 36 additions & 0 deletions DashedDivider.kt
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,36 @@
    @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
    )
    )
    )
    }
    }