h6ah4i / android-advancedrecyclerview

RecyclerView extension library which provides advanced features. (ex. Google's Inbox app like swiping, Play Music app like drag and drop sorting)
https://advancedrecyclerview.h6ah4i.com/
Apache License 2.0
5.31k stars 862 forks source link

Draggable GRID LAYOUT,other items flash on long pressed #377

Open gewuxy opened 7 years ago

gewuxy commented 7 years ago

I find that some items would flash sometimes on long pressed, it seems that it is caused by the following code in DraggableItemWrapperAdapter: ` void onDragItemStarted(DraggingItemInfo draggingItemInfo, RecyclerView.ViewHolder holder, ItemDraggableRange range, int wrappedItemPosition, int itemMoveMode) { if (LOCAL_LOGD) { Log.d(TAG, "onDragItemStarted(holder = " + holder + ")"); }

    if (DEBUG_BYPASS_MOVE_OPERATION_MODE) {
        return;
    }

    if (holder.getItemId() == RecyclerView.NO_ID) {
        throw new IllegalStateException("dragging target must provides valid ID");
    }

    mDraggableItemAdapter = WrapperAdapterUtils.findWrappedAdapter(this, DraggableItemAdapter.class, wrappedItemPosition);

    if (mDraggableItemAdapter == null) {
        throw new IllegalStateException("DraggableItemAdapter not found!");
    }

    mDraggingItemInitialPosition = mDraggingItemCurrentPosition = wrappedItemPosition;
    mDraggingItemInfo = draggingItemInfo;
    mDraggingItemViewHolder = holder;
    mDraggableRange = range;
    mItemMoveMode = itemMoveMode;

    notifyDataSetChanged();
}

void onDragItemFinished(boolean result) { if (LOCAL_LOGD) { Log.d(TAG, "onDragItemFinished(result = " + result + ")"); }

    if (DEBUG_BYPASS_MOVE_OPERATION_MODE) {
        return;
    }

    if (result && (mDraggingItemCurrentPosition != mDraggingItemInitialPosition)) {
        // apply to wrapped adapter
        mDraggableItemAdapter.onMoveItem(mDraggingItemInitialPosition, mDraggingItemCurrentPosition);
    }

    mDraggingItemInitialPosition = RecyclerView.NO_POSITION;
    mDraggingItemCurrentPosition = RecyclerView.NO_POSITION;
    mDraggableRange = null;
    mDraggingItemInfo = null;
    mDraggingItemViewHolder = null;
    mDraggableItemAdapter = null;

    notifyDataSetChanged();
}`

notifyDataSetChanged() needed here?

after remove it, the flash disappear.

h6ah4i commented 7 years ago

Hi. Have you disabled change animations like this?

((SimpleItemAnimator) recyclerView.getItemAnimator()).setSupportsChangeAnimations(false);

I find that some items would flash sometimes on long pressed, it seems that it is caused by the following code in DraggableItemWrapperAdapter:

Actually, those notifyDataSetChanged() calls may not be required as you pointed it out. At least, this library expects to update dragging state flags (= setDragStateFlags()) of all items on start/finish dragging, so probably they can be replaced to notifyItemRangeChanged() with a payload parameter. However, I am not willing to change them because;

gewuxy commented 7 years ago

you have disable change animation in DraggableItemAnimator

@Override protected void onSetup() { super.onSetup(); super.setSupportsChangeAnimations(false); }

gewuxy commented 7 years ago

the animation is fresco's fade-in animation, but after disable fade-in duration, some item still flash unexpectedly