fix: 修复ViewStub偶发闪退问题 https://sentry.shanqu.cc/organizations/lightgame/issues/422108/events/?project=22 https://sentry.shanqu.cc/organizations/lightgame/issues/425087/?project=22
This commit is contained in:
@ -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 }
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@ -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
|
||||
}
|
||||
Reference in New Issue
Block a user