Last active
December 27, 2022 03:12
-
-
Save NonCoderF/265cee7be646391672a4de442061dbc4 to your computer and use it in GitHub Desktop.
Jetpack compose chat box path sample
This file contains 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.Column | |
import androidx.compose.foundation.layout.fillMaxWidth | |
import androidx.compose.runtime.* | |
import androidx.compose.ui.Modifier | |
import androidx.compose.ui.draw.drawBehind | |
import androidx.compose.ui.graphics.Color | |
import androidx.compose.ui.graphics.Path | |
import androidx.compose.ui.graphics.drawscope.Stroke | |
import androidx.compose.ui.layout.onGloballyPositioned | |
import androidx.compose.ui.unit.dp | |
import androidx.compose.ui.unit.toSize | |
@Composable | |
fun ChatBox( | |
modifier: Modifier = Modifier, | |
) { | |
var width by remember { mutableStateOf(0f) } | |
var height by remember { mutableStateOf(0f) } | |
val gradientSize = 24.dp.value | |
val path = Path().apply { | |
moveTo(0f, 0f) | |
lineTo(gradientSize, gradientSize) | |
lineTo(width - gradientSize, gradientSize) | |
cubicTo( | |
width - gradientSize, gradientSize, | |
width, gradientSize, | |
width, gradientSize + gradientSize | |
) | |
lineTo(width, gradientSize + gradientSize) | |
lineTo(width, height - gradientSize) | |
cubicTo( | |
width, height - gradientSize, | |
width, height, | |
width - gradientSize, height | |
) | |
lineTo(width - gradientSize, height) | |
lineTo(0f + gradientSize, height) | |
cubicTo( | |
0f + gradientSize, height, | |
0f, height, | |
0f, height - gradientSize | |
) | |
lineTo(0f, height - gradientSize) | |
lineTo(0f, 0f) | |
close() | |
} | |
Column( | |
modifier = modifier | |
.fillMaxWidth() | |
.onGloballyPositioned { | |
width = it.size.toSize().width | |
height = it.size.toSize().height | |
} | |
.drawBehind { | |
drawPath( | |
color = Color.White, | |
path = path, | |
style = Stroke(2.dp.value) | |
) | |
}) | |
{ | |
//Content goes here | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment