Colton Idle
02/18/2021, 4:05 AMHalil Ozercan
02/18/2021, 5:21 AMSamir Basnet
02/18/2021, 1:34 PMNader Jawad
02/18/2021, 10:11 PMfun Modifier.banner(): Modifier {
val bannerHeight = 50.dp
val bannerWidth = 80.dp
val tailWidth = 15.dp
val tailHeight = 15.dp
val tailPadding = 2.dp
return this.then(Modifier.drawWithCache {
val bannerPath = Path().apply {
addRoundRect(
RoundRect(
left = size.width + tailWidth.toPx() - bannerWidth.toPx(),
top = size.height / 2 - bannerHeight.toPx() / 2,
right = size.width + tailWidth.toPx(),
bottom = size.height / 2 + bannerHeight.toPx() / 2,
topLeftCornerRadius = CornerRadius(15f),
bottomLeftCornerRadius = CornerRadius(15f),
bottomRightCornerRadius = CornerRadius(15f)
)
)
}
val bannerTailOuter = Path().apply {
addRoundRect(
RoundRect(
left = size.width,
top = size.height / 2 - bannerHeight.toPx() / 2 - tailHeight.toPx(),
right = size.width + tailWidth.toPx(),
bottom = size.height / 2 - bannerHeight.toPx() / 2,
topRightCornerRadius = CornerRadius(15f)
)
)
}
val bannerTailInner = Path().apply {
addRoundRect(
RoundRect(
left = size.width,
top = size.height / 2 - bannerHeight.toPx() / 2 - tailHeight.toPx() +
tailPadding.toPx(),
right = size.width + tailWidth.toPx() - tailPadding.toPx(),
bottom = size.height / 2 - bannerHeight.toPx() / 2,
topRightCornerRadius = CornerRadius(15f),
bottomRightCornerRadius = CornerRadius(15f)
)
)
}
onDrawWithContent {
drawPath(bannerTailOuter, Color.Gray)
drawPath(bannerTailInner, Color.DarkGray)
drawContent()
drawPath(bannerPath, Color.Gray)
}
})
}
@Composable
fun BannerDemo() {
Box(modifier = Modifier.fillMaxSize()) {
Box(modifier = Modifier.size(200.dp).background(Color.Blue).banner())
}
}
Colton Idle
02/18/2021, 11:38 PMNader Jawad
02/18/2021, 11:40 PM