fix some crash while itemanimator is opened

This commit is contained in:
侯歌 2024-05-15 10:53:55 +08:00
parent 744a8f2ab5
commit 04f05b94f5
2 changed files with 10 additions and 8 deletions

View File

@ -2897,12 +2897,12 @@ void RecyclerView::offsetPositionRecordsForRemove(int positionStart, int itemCou
ViewHolder* holder = getChildViewHolderInt(mChildHelper->getUnfilteredChildAt(i));
if (holder && !holder->shouldIgnore()) {
if (holder->mPosition >= positionEnd) {
LOGD("offsetPositionRecordsForRemove attached child %d hold %p now at position %d",i
,holder, (holder->mPosition - itemCount));
LOGD("offsetPositionRecordsForRemove attached child %d(%p) hold %p now at position %d",
i,holder->itemView ,holder, (holder->mPosition - itemCount));
holder->offsetPosition(-itemCount, applyToPreLayout);
mState->mStructureChanged = true;
} else if (holder->mPosition >= positionStart) {
LOGD("offsetPositionRecordsForRemove attached child %d holder %p now REMOVED",i,holder);
LOGD("offsetPositionRecordsForRemove attached child %d(%p) holder %p now REMOVED",i,holder->itemView,holder);
holder->flagRemovedAndOffsetPosition(positionStart - 1, -itemCount,applyToPreLayout);
mState->mStructureChanged = true;
}
@ -6009,6 +6009,8 @@ RecyclerView::ViewHolder::ViewHolder(View* itemView) {
FATAL_IF(itemView == nullptr,"itemView may not be null");
this->itemView = itemView;
mFlags = 0;
mIsRecyclableCount = 0;
mInChangeScrap = false;
mPosition = NO_POSITION;
mOldPosition = NO_POSITION;
mPreLayoutPosition = NO_POSITION;

View File

@ -23,10 +23,10 @@ bool SimpleItemAnimator::animateDisappearance(RecyclerView::ViewHolder& viewHold
disappearingItemView->layout(newLeft, newTop,
newLeft + disappearingItemView->getWidth(),
newTop + disappearingItemView->getHeight());
LOGD_IF(_DEBUG,"DISAPPEARING: %p with view %p",viewHolder,disappearingItemView);
LOGD_IF(_DEBUG,"DISAPPEARING: %p with view %p",&viewHolder,disappearingItemView);
return animateMove(viewHolder, oldLeft, oldTop, newLeft, newTop);
} else {
LOGD_IF(_DEBUG,"REMOVED: %p with view %p",viewHolder,disappearingItemView);
LOGD_IF(_DEBUG,"REMOVED: %p with view %p",&viewHolder,disappearingItemView);
return animateRemove(viewHolder);
}
}
@ -36,7 +36,7 @@ bool SimpleItemAnimator::animateAppearance(RecyclerView::ViewHolder& viewHolder,
if (preLayoutInfo != nullptr && (preLayoutInfo->left != postLayoutInfo.left
|| preLayoutInfo->top != postLayoutInfo.top)) {
// slide items in if before/after locations differ
LOGD_IF(_DEBUG,"APPEARING: %p with view %p" ,viewHolder,viewHolder);
LOGD_IF(_DEBUG,"APPEARING: %p with view %p" ,&viewHolder,viewHolder.itemView);
return animateMove(viewHolder, preLayoutInfo->left, preLayoutInfo->top,
postLayoutInfo.left, postLayoutInfo.top);
} else {
@ -48,7 +48,7 @@ bool SimpleItemAnimator::animateAppearance(RecyclerView::ViewHolder& viewHolder,
bool SimpleItemAnimator::animatePersistence(RecyclerView::ViewHolder& viewHolder,
ItemHolderInfo& preInfo, ItemHolderInfo& postInfo) {
if (preInfo.left != postInfo.left || preInfo.top != postInfo.top) {
LOGD_IF(_DEBUG,"PERSISTENT: %p with view %p",viewHolder,viewHolder.itemView);
LOGD_IF(_DEBUG,"PERSISTENT: %p with view %p",&viewHolder,viewHolder.itemView);
return animateMove(viewHolder, preInfo.left, preInfo.top, postInfo.left, postInfo.top);
}
dispatchMoveFinished(viewHolder);
@ -57,7 +57,7 @@ bool SimpleItemAnimator::animatePersistence(RecyclerView::ViewHolder& viewHolder
bool SimpleItemAnimator::animateChange(RecyclerView::ViewHolder& oldHolder, RecyclerView::ViewHolder& newHolder,
ItemHolderInfo& preInfo, ItemHolderInfo& postInfo) {
LOGD_IF(_DEBUG,"CHANGED: %p with view %p",oldHolder,oldHolder.itemView);
LOGD_IF(_DEBUG,"CHANGED: %p with view %p",&oldHolder,oldHolder.itemView);
const int fromLeft = preInfo.left;
const int fromTop = preInfo.top;
int toLeft, toTop;