Skip to content

Instantly share code, notes, and snippets.

@NonCoderF
Last active December 27, 2022 03:12
Show Gist options
  • Save NonCoderF/265cee7be646391672a4de442061dbc4 to your computer and use it in GitHub Desktop.
Save NonCoderF/265cee7be646391672a4de442061dbc4 to your computer and use it in GitHub Desktop.
Jetpack compose chat box path sample
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