Skip to content

Commit

Permalink
[优化] 避免重复状态刷新
Browse files Browse the repository at this point in the history
  • Loading branch information
Zhao-Yan-Yan committed Mar 6, 2021
1 parent fe220ab commit b46f463
Showing 1 changed file with 21 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,12 @@ import com.zy.multistatepage.state.SuccessState
@SuppressLint("ViewConstructor")
class MultiStateContainer : FrameLayout {

var originTargetView: View? = null

var onRetryEventListener: OnRetryEventListener? = null

private var originTargetView: View? = null

private var lastState: String = ""

constructor(
context: Context,
originTargetView: View,
Expand All @@ -34,14 +36,20 @@ class MultiStateContainer : FrameLayout {
this.onRetryEventListener = onRetryEventListener
}

constructor(context: Context, attrs: AttributeSet?) : this(context, attrs, 0)
constructor(context: Context, attrs: AttributeSet?, defStyleAttr: Int) : super(context, attrs, defStyleAttr) {
constructor(
context: Context,
attrs: AttributeSet?
) : this(context, attrs, 0)

}
constructor(
context: Context,
attrs: AttributeSet?,
defStyleAttr: Int
) : super(context, attrs, defStyleAttr)

override fun onFinishInflate() {
super.onFinishInflate()
if (childCount == 1) {
if (originTargetView == null && childCount == 1) {
originTargetView = getChildAt(0)
}
}
Expand All @@ -66,6 +74,13 @@ class MultiStateContainer : FrameLayout {

@JvmOverloads
fun <T : MultiState> show(multiState: T, enableAnimator: Boolean = true, onNotifyListener: OnNotifyListener<T>? = null) {

if (lastState == multiState.javaClass.name) {
return
}

lastState = multiState.javaClass.name

if (childCount == 0) {
initialization()
}
Expand Down

0 comments on commit b46f463

Please sign in to comment.