Skip to content

Instantly share code, notes, and snippets.

View cp-radhika-s's full-sized avatar
🎯
Focusing

Radhika canopas cp-radhika-s

🎯
Focusing
View GitHub Profile
@OptIn(ExperimentalTextApi::class)
@Composable
fun ExampleTextOverFlow() {
val textMeasure = rememberTextMeasurer()
Canvas(
onDraw = {
drawRect(color = Color.Black)
@OptIn(ExperimentalTextApi::class)
@Composable
fun ExampleTextLayoutResult() {
val textMeasure = rememberTextMeasurer()
var textLayoutResult by remember { mutableStateOf<TextLayoutResult?>(null) }
Canvas(
modifier = Modifier
.fillMaxWidth()
.height(100.dp)
val textMeasure = rememberTextMeasurer()
var textLayoutResult by remember { mutableStateOf<TextLayoutResult?>(null) }
Canvas(
modifier = Modifier
.layout { measurable, constraints ->
val placeable = measurable.measure(constraints)
textLayoutResult = textMeasure.measure(
AnnotatedString("Text on Canvas!"),
@ExperimentalTextApi
fun DrawScope.drawText(
textLayoutResult: TextLayoutResult,
color: Color = Color.Unspecified,
topLeft: Offset = Offset.Zero,
alpha: Float = Float.NaN,
shadow: Shadow? = null,
textDecoration: TextDecoration? = null
){}
@ExperimentalTextApi
@Composable
fun ExampleTextString() {
val textMeasure = rememberTextMeasurer()
Canvas(modifier = Modifier
.fillMaxWidth()
.height(100.dp), onDraw = {
drawRect(color = Color.Black)
@ExperimentalTextApi
fun DrawScope.drawText(
textMeasurer: TextMeasurer,
text: String,
// Other configuration
)
@OptIn(ExperimentalTextApi::class)
@Composable
fun ExampleTextAnnotatedString() {
val textMeasure = rememberTextMeasurer()
val text = buildAnnotatedString {
withStyle(
style = SpanStyle(
color = Color.White,
fun DrawScope.drawText(
textMeasurer: TextMeasurer,
text: AnnotatedString,
// other configuration...
)
@Composable
fun NativeDrawText() {
val paint = Paint().asFrameworkPaint().apply {
// paint configuration
}
Canvas(modifier = Modifier
.fillMaxWidth()
.height(100.dp), onDraw = {
@Composable
fun NoRippleEffect3() {
CompositionLocalProvider(LocalRippleTheme provides NoRippleTheme) {
Button(
onClick = {
//Clicked
}, shape = RoundedCornerShape(12.dp),
contentPadding = PaddingValues(16.dp)
) {
Text(text = "Click me")