Skip to content

Instantly share code, notes, and snippets.

@mahendranv
Created Jul 9, 2021
Embed
What would you like to do?
A tag shape
import androidx.compose.foundation.layout.Box
import androidx.compose.foundation.layout.padding
import androidx.compose.foundation.shape.GenericShape
import androidx.compose.material.Surface
import androidx.compose.material.Text
import androidx.compose.runtime.Composable
import androidx.compose.ui.Modifier
import androidx.compose.ui.tooling.preview.Preview
import androidx.compose.ui.unit.dp
import com.ex2.dribbble.ui.theme.DribbleUITheme
val TagShape3 = GenericShape { size, _ ->
val w = size.width / 27f
val h = size.height / 11f
moveTo(5f * w, 0f * h)
lineTo(25f * w, 0f * h)
cubicTo(26f * w, 0f, 27f * w, 1f * h, 27f * w, 2f * h)
lineTo(27f * w, 9f * h)
cubicTo(27f * w, 10f * h, 26f * w, 11f * h, 25f * w, 11f * h)
lineTo(5f * w, 11f * h)
lineTo(1f * w, 7f * h)
cubicTo(0f * w, 6f * h, 0f * w, 5f * h, 1f * w, 4f * h)
}
@Composable
fun TagView(tag: String, modifier: Modifier = Modifier) {
Surface(
color = color_green,
shape = TagShape3,
) {
Text(
text = tag,
modifier = Modifier.padding(start = 40.dp, end = 8.dp, top = 8.dp, bottom = 8.dp)
)
}
}
@Preview(showBackground = true)
@Composable
fun previewTagShape() {
DribbleUITheme {
Box(modifier = Modifier.padding(24.dp)) {
TagView(tag = "Compose")
}
}
}
@mahendranv
Copy link
Author

mahendranv commented Jul 9, 2021

image

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment