如何通过事件有效地处理和关闭Android Jetpack Compose中的Popup widget?通过布尔标志使弹出窗口不可见会抛出不正确解除的警告。
Input channel object '5668e46 Pop-Up Window (client)' was disposed without first being removed with the input manager!
if (showOverlay) {
println(buttonPosition)
val popup = Popup(
onDismissRequest = {
showOverlay = false
},
offset = IntOffset(
LocalConfiguration.current.screenWidthDp, buttonPosition.y.toInt() + 48
)
) {
Box(
modifier = Modifier
.background(Color.LightGray.copy(alpha = 0.7F))
.padding(16.dp)
) {
// Content
}
}
}
1条答案
按热度按时间azpvetkf1#
你得到警告的原因是因为弹出窗口没有经过必要的清理过程就被释放了。要正确地释放弹出窗口,你需要使用在重组过程中记住的状态。以下是如何在jetpack compose中实现sate:
创建状态后: