• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download

<lambda>null1 package com.android.systemui.shade.ui.composable
2 
3 import androidx.compose.material3.MaterialTheme
4 import androidx.compose.material3.Text
5 import androidx.compose.runtime.Composable
6 import androidx.compose.ui.Modifier
7 import androidx.compose.ui.graphics.Color
8 import androidx.compose.ui.layout.Layout
9 
10 @Composable
11 fun VariableDayDate(
12     longerDateText: String,
13     shorterDateText: String,
14     textColor: Color,
15     modifier: Modifier = Modifier,
16 ) {
17     Layout(
18         contents =
19             listOf(
20                 {
21                     Text(
22                         text = longerDateText,
23                         style = MaterialTheme.typography.bodyMedium,
24                         color = textColor,
25                         maxLines = 1,
26                     )
27                 },
28                 {
29                     Text(
30                         text = shorterDateText,
31                         style = MaterialTheme.typography.bodyMedium,
32                         color = textColor,
33                         maxLines = 1,
34                     )
35                 },
36             ),
37         modifier = modifier,
38     ) { measureables, constraints ->
39         check(measureables.size == 2)
40         check(measureables[0].size == 1)
41         check(measureables[1].size == 1)
42 
43         val longerMeasurable = measureables[0][0]
44         val shorterMeasurable = measureables[1][0]
45 
46         val longerPlaceable = longerMeasurable.measure(constraints)
47         val shorterPlaceable = shorterMeasurable.measure(constraints)
48 
49         // If width < maxWidth (and not <=), we can assume that the text fits.
50         val placeable =
51             when {
52                 longerPlaceable.width < constraints.maxWidth &&
53                     longerPlaceable.height <= constraints.maxHeight -> longerPlaceable
54                 shorterPlaceable.width < constraints.maxWidth &&
55                     shorterPlaceable.height <= constraints.maxHeight -> shorterPlaceable
56                 else -> null
57             }
58 
59         layout(placeable?.width ?: 0, placeable?.height ?: 0) { placeable?.placeRelative(0, 0) }
60     }
61 }
62