Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

重复设置显示布局时removeStatus问题 #35

Open
skybdemq opened this issue Aug 14, 2024 · 1 comment
Open

重复设置显示布局时removeStatus问题 #35

skybdemq opened this issue Aug 14, 2024 · 1 comment

Comments

@skybdemq
Copy link

skybdemq commented Aug 14, 2024

private fun removeStatus(status: Status) {
    statusMap.remove(status)
}

removeStatus方法只是将相关的StatusInfo信息删除,需要判断该StatusInfo引用的View是否已添加到statelayout,如果已添加需要调用removeView将其删除。

如下面代码,如果根据不同情况设置不同的空页面布局并显示空页面,在不同情况间切换时

if (isOpen) {
    mViewBinding.stateLayout.emptyLayout = R.layout.live_empty_layout
    mViewBinding.tvSwitch.setText(R.string.live_on)
    mViewBinding.stateLayout.showEmpty("on")
} else {
    mViewBinding.stateLayout.emptyLayout = R.layout.live_layout_rtc_connect_off
    mViewBinding.tvSwitch.setText(R.string.live_off)
    mViewBinding.stateLayout.showEmpty("off")
}

设置emptyLayout会调用 removeStatus(EMPTY)将之前empty的StatusInfo从statusMap中删除,但原来的emptyView依然存在statelayout中

var emptyLayout: Int = NO_ID
get() = if (field == NO_ID) StateConfig.emptyLayout else field
set(value) {
    if (field != value) {
        removeStatus(EMPTY)
        field = value
    }
}

当调用showEmpty方法最终会showStatus执行

statusMap.filter {
    it.key != status
}.forEach {
    val statusInfo = it.value
    if (it.key == this.status) {
        stateChangedHandler.onRemove(this, statusInfo.view, it.key, statusInfo.tag)
    }
}

showStatus中这段代码是将上一状态的视图对象visibility设置为GONE,但由于之前重新设置emptyLayout时已将上一个empty的StatusInfo从statusMap删除,所以无法将原来的emptyView隐藏或删除

@liangjingkanji
Copy link
Owner

不太清楚你问的什么问题

如果只是想自定义不同的空布局页面, 可以直接在onEmpty中设置View最简单: 多状态

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants