在片段的XML ui代码中使用AbstractComposeView固有的合成视图知道该片段是导航图的一部分(Jetpack导航)当我按下返回按钮返回到我的片段时,合成视图刚刚消失。它只是我第一次打开片段时绘制的。
波纹管视图代码
class ProgressComposeView @JvmOverloads constructor(
context: Context,
attrs: AttributeSet? = null,
defStyleAttr: Int = 0
) : AbstractComposeView(context, attrs, defStyleAttr) {
private var steps = mutableStateOf(0)
private var currentStep: Int = 0
private var windowWidth: Int = 0
@Composable
override fun Content() {
ProgressView(steps.value, currentStep, windowWidth)
}
fun setData(steps: Int, currentStep: Int, windowWidth: Int) {
this.steps.value = steps
this.currentStep = currentStep
this.windowWidth = windowWidth
}
}
@Composable
fun ProgressView(totalSteps: Int, currentStep: Int, windowWidth: Int) {
..... }
1条答案
按热度按时间kcwpcxri1#
解决方案:
您必须在
ComposeView
上调用.disposeComposition()
在onResume()函数中
示例: