Skip to content

Commit e97ff56

Browse files
committed
Merge remote-tracking branch 'origin/master'
2 parents 73b013b + 91d6cc8 commit e97ff56

File tree

1 file changed

+26
-1
lines changed

1 file changed

+26
-1
lines changed

library/src/main/java/com/jmedeisis/draglinearlayout/DragLinearLayout.java

Lines changed: 26 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,8 @@ public interface OnViewSwapListener {
6161

6262
private OnViewSwapListener swapListener;
6363

64+
private LayoutTransition layoutTransition;
65+
6466
/**
6567
* Mapping from child index to drag-related info container.
6668
* Presence of mapping implies the child can be dragged, and is considered for swaps with the
@@ -262,6 +264,11 @@ public void addDragView(View child, View dragHandle, int index) {
262264
* Makes the child a candidate for dragging. Must be an existing child of this layout.
263265
*/
264266
public void setViewDraggable(View child, View dragHandle) {
267+
if (null == child || null == dragHandle) {
268+
throw new IllegalArgumentException(
269+
"Draggable children and their drag handles must not be null.");
270+
}
271+
265272
if (this == child.getParent()) {
266273
dragHandle.setOnTouchListener(new DragHandleOnTouchListener(child));
267274
draggableChildren.put(indexOfChild(child), new DraggableChild());
@@ -296,6 +303,12 @@ public void removeDragView(View child) {
296303
}
297304
}
298305

306+
@Override
307+
public void removeAllViews() {
308+
super.removeAllViews();
309+
draggableChildren.clear();
310+
}
311+
299312
/**
300313
* If this layout is within a {@link android.widget.ScrollView}, register it here so that it
301314
* can be scrolled during item drags.
@@ -351,6 +364,13 @@ private void startDetectingDrag(View child) {
351364
}
352365

353366
private void startDrag() {
367+
// remove layout transition, it conflicts with drag animation
368+
// we will restore it after drag animation end, see onDragStop()
369+
layoutTransition = getLayoutTransition();
370+
if (layoutTransition != null) {
371+
setLayoutTransition(null);
372+
}
373+
354374
draggedItem.onDragStart();
355375
requestDisallowInterceptTouchEvent(true);
356376
}
@@ -392,6 +412,11 @@ public void onAnimationEnd(Animator animation) {
392412

393413
if (null != dragTopShadowDrawable) dragTopShadowDrawable.setAlpha(255);
394414
dragBottomShadowDrawable.setAlpha(255);
415+
416+
// restore layout transition
417+
if (layoutTransition != null && getLayoutTransition() == null) {
418+
setLayoutTransition(layoutTransition);
419+
}
395420
}
396421
});
397422
draggedItem.settleAnimation.start();
@@ -726,4 +751,4 @@ private static Bitmap getBitmapFromView(View view) {
726751
view.draw(canvas);
727752
return bitmap;
728753
}
729-
}
754+
}

0 commit comments

Comments
 (0)