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

修复SwipeRefreshLayout空指针异常 #672

Open
wants to merge 3 commits into
base: master
Choose a base branch
from

Conversation

TestPlanB
Copy link

fix #541
SwipeRefreshLayout 的reset方法在onDetachedFromWindow和mRefreshListener的onAnimationEnd都会调用,
void reset() {
mCircleView.clearAnimation();
mProgress.stop();
mCircleView.setVisibility(View.GONE);
setColorViewAlpha(MAX_ALPHA);
// Return the circle to its start position
if (mScale) {
setAnimationProgress(0 /* animation complete and view is hidden */);
} else {
setTargetOffsetTopAndBottom(mOriginalOffsetTop - mCurrentTargetOffsetTop);
}
mCurrentTargetOffsetTop = mCircleView.getTop();
}

mCircleView.clearAnimation后会回调onAnimationEnd,所以可能出现一种情况在onDetachedFromWindow后回调了监听器或者其他过程调用reset,里面都用到的了setAlpha,如果ActivityLeakFixer清除drawable资源就会导致外部的SwipeRefreshLayout调用出现异常。
SwipeRefreshLayout 这个库只是更多时候希望重置drawable,没有想要设置为null,因此ActivityLeakFixer忽略跳过删除drawable会比较好。

@Yves0
Copy link
Collaborator

Yves0 commented Nov 16, 2021

请问有可以复现的代码吗?可能在某些特殊情况下 Activity destroy 后重复回调了 onDetachedFromWindow,看看有没有除了加白之外的解法

@Yves0
Copy link
Collaborator

Yves0 commented Nov 16, 2021

请问有可以复现的代码吗?可能在某些特殊情况下 Activity destroy 后重复回调了 onDetachedFromWindow,看看有没有除了加白之外的解法

SwipeRefreshLayout#reset 一共有四个地方调用: onAnimationEnd onDetachedFromWindow setEnabled(false)setProgressViewOffset,我只在后两者错误使用的情况下(destroy 之后调用)复现问题,但 issue #540 中反馈的在 onDetach 发生 NPE 的情况没有复现

@TestPlanB
Copy link
Author

TestPlanB commented Nov 16, 2021 via email

@TestPlanB
Copy link
Author

TestPlanB commented Nov 16, 2021 via email

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

Successfully merging this pull request may close these issues.

引入后会造成跟 SwipeRefreshLayout 冲突引起闪退报错空指针异常
2 participants