airbnb / epoxy

Epoxy is an Android library for building complex screens in a RecyclerView
https://goo.gl/eIK82p
Apache License 2.0
8.51k stars 728 forks source link

Use EpoxyTouchHelper but happen crash,ArrayIndexOutofBoundsException #1346

Closed Chenyulun1028 closed 1 year ago

Chenyulun1028 commented 1 year ago

epoxy_version = '2.19.0'

I implement a function, when I test effect the first abnormal condition: I noticed that the drag problem automatically ended for item before my finger left the screen,I Debugging through breakpoints,the call chain is onAnimationFinished -> removeAnimatingView -> this.mChildHelper.removeViewIfHidden(view) -> this.mCallback.removeViewAt(index), both the dragging item and new position item are removed

the second abnormal condition: it happen crash image

the dragging implementation as follow: ` private void initDragging() { EpoxyTouchHelper.initDragging(taskController) .withRecyclerView(rvTasks) .forVerticalList() .withTarget(ProjectTaskTemplateModel.class) .andCallbacks(new DragCallbacks() { ValueAnimator backgroundAnimator = null;

      @Override
      public void onDragStarted(ProjectTaskTemplateModel model, final View itemView,
          int adapterPosition) {
        if (!isShowSortStyle) {
          return;
        }
        backgroundAnimator = ValueAnimator.ofObject(new ArgbEvaluator(), white, white);
        backgroundAnimator.addUpdateListener(new AnimatorUpdateListener() {
          @Override
          public void onAnimationUpdate(ValueAnimator animator) {
            itemView.setBackgroundColor((int) animator.getAnimatedValue());
          }
        });
        backgroundAnimator.start();
        itemView.animate().scaleX(1.05f).scaleY(1.05f);
      }

      @Override
      public void onDragReleased(ProjectTaskTemplateModel model, final View itemView) {
        if (!isShowSortStyle) {
          return;
        }
        if (backgroundAnimator != null) {
          backgroundAnimator.cancel();
        }

        backgroundAnimator = ValueAnimator.ofObject(
            new ArgbEvaluator(), ((ColorDrawable) itemView.getBackground()).getColor(), white
        );

        backgroundAnimator.addUpdateListener(new AnimatorUpdateListener() {
          @Override
          public void onAnimationUpdate(ValueAnimator animator) {
            itemView.setBackgroundColor((int) animator.getAnimatedValue());
          }
        });
        backgroundAnimator.start();
        itemView.animate().scaleX(1f).scaleY(1f);
      }

      @Override
      public void onModelMoved(int fromPosition, int toPosition,
          ProjectTaskTemplateModel modelBeingMoved, View view) {
        if (!isShowSortStyle) {
          return;
        }

        Task remove = topLevelTaskList.remove(fromPosition);
        topLevelTaskList.add(toPosition, remove);
      }
    });

}`

when I comment onModelMoved inside code,the drag effect is ok,but the drag item will go back origin position when finish dragging item and I have a Very similar recyclerview,it don't happen above-mentioned and work right,two recyclerviews is in same activity

sorry,my english is bad @elihart

Chenyulun1028 commented 1 year ago

I find crash resson, it's like item be detached from window,so not found image

Chenyulun1028 commented 1 year ago

image ok, I solve this question, the model id can't set like this