叶子维
2025-01-09 11:25:09 +08:00
parent 9744b95126
commit dc2e7147d9
6 changed files with 19 additions and 14 deletions

View File

@ -4,6 +4,7 @@ import android.os.Bundle
import android.view.View
import android.view.ViewStub
import com.gh.gamecenter.common.R
import com.gh.gamecenter.common.utils.inflateOrShow
/**
* 这是在 BaseLazyFragment 之上添加了一些通用功能的抽象类
@ -66,11 +67,7 @@ abstract class LazyFragment : BaseLazyFragment() {
} else {
mViewStub?.layoutResource = getRealLayoutId()
mViewStub?.setOnInflateListener { _, inflatedView -> onRealLayoutInflated(inflatedView) }
if (mViewStub?.parent != null) {
mViewStub?.inflate()?.let { mCachedView = it }
} else {
mViewStub?.visibility = View.VISIBLE
}
mViewStub?.inflateOrShow()?.let { mCachedView = it }
}
}

View File

@ -1704,4 +1704,12 @@ fun RecyclerView.tryToClearRecycler() {
} catch (e: java.lang.Exception) {
e.printStackTrace()
}
}
}
fun ViewStub.inflateOrShow(): View? =
if (parent != null) {
inflate()
} else {
visibility = View.VISIBLE
null
}