The code below works fine on Android 14-, but on Android 15, the bottom of the Tooltip is truncated:
The bottom of the red border is missing, and only the top part of the letter 'g' is visible.
Looks like it's missing the height of the top status bar, how to fix it? The code:
class MainActivity : ComponentActivity() {
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
enableEdgeToEdge()
var veryLongTooltip = ""
for (i in 0..60) { // generate 60 lines
veryLongTooltip += "$i\n"
}
veryLongTooltip += "\n" + "last line aaaaaa bbbbbbb cccccc dddddd eeeeee fffffff ggggggg"
setContent {
TestTheme {
Scaffold { innerPadding ->
Column(
modifier = Modifier.padding(innerPadding),
) {
TooltipButton(tooltipText = veryLongTooltip)
}
}
}
}
}
}
@OptIn(ExperimentalMaterial3Api::class)
@Composable
fun TooltipButton(tooltipText: String) {
val tooltipState = rememberTooltipState(isPersistent = true)
TooltipBox(
positionProvider = TooltipDefaults.rememberRichTooltipPositionProvider(),
tooltip = {
RichTooltip(
shape = RoundedCornerShape(5.dp),
modifier = Modifier
.border(4.dp, Color.Red, shape = RoundedCornerShape(5.dp))
) {
Text(
tooltipText,
fontSize = 18.sp,
modifier = Modifier.verticalScroll(rememberScrollState())
)
}
},
state = tooltipState
) {
val coroutine = rememberCoroutineScope()
Button(
onClick = {
coroutine.launch { tooltipState.show() }
}
) {
Text("click to show the tooltip")
}
}
}
Edited:
Not sure why it happens, I ended up using a workaround to limit the max height of the Text to 90% of the screen.
@Composable
fun Modifier.maxScreenHeight(percentage: Float): Modifier = composed {
val ctx = LocalContext.current
val density = LocalDensity.current
val maxHeight = density.run {
val screenHeightPx = ctx.resources.displayMetrics.heightPixels
screenHeightPx.toDp().value * percentage
}
this.then(
Modifier.heightIn(max = maxHeight.dp)
)
}
