diff --git a/doric-android/doric/src/main/java/pub/doric/shader/list/ListNode.java b/doric-android/doric/src/main/java/pub/doric/shader/list/ListNode.java index 4df3f197..7dabf2a5 100644 --- a/doric-android/doric/src/main/java/pub/doric/shader/list/ListNode.java +++ b/doric-android/doric/src/main/java/pub/doric/shader/list/ListNode.java @@ -15,6 +15,8 @@ */ package pub.doric.shader.list; +import static androidx.recyclerview.widget.ItemTouchHelper.ACTION_STATE_DRAG; + import android.annotation.SuppressLint; import android.content.Context; import android.text.TextUtils; @@ -87,6 +89,13 @@ public class ListNode extends SuperNode implements IDoricScrollabl } + @Override + public void beforeMove(int fromPos) { + if (!TextUtils.isEmpty(beforeDraggingFuncId)) { + callJSResponse(beforeDraggingFuncId, fromPos); + } + } + @Override public boolean onMove(int srcPosition, int targetPosition) { String srcValue = itemValues.valueAt(srcPosition); @@ -109,6 +118,7 @@ public class ListNode extends SuperNode implements IDoricScrollabl } ); + private String beforeDraggingFuncId; private String onDraggingFuncId; private String onDraggedFuncId; @@ -309,6 +319,12 @@ public class ListNode extends SuperNode implements IDoricScrollabl boolean canDrag = prop.asBoolean().value(); doricItemTouchHelperCallback.setDragEnable(canDrag); break; + case "beforeDragging": + if (!prop.isString()) { + return; + } + this.beforeDraggingFuncId = prop.asString().value(); + break; case "onDragging": if (!prop.isString()) { return; @@ -434,8 +450,9 @@ public class ListNode extends SuperNode implements IDoricScrollabl onScrollFuncId = null; onScrollEndFuncId = null; renderItemFuncId = null; - onDraggedFuncId = null; + beforeDraggingFuncId = null; onDraggingFuncId = null; + onDraggedFuncId = null; } private static class DoricItemTouchHelper extends ItemTouchHelper { @@ -522,6 +539,12 @@ public class ListNode extends SuperNode implements IDoricScrollabl if (viewHolder != null) { fromPos = viewHolder.getAdapterPosition(); } + + if (actionState == ACTION_STATE_DRAG) { + if (onItemTouchCallbackListener != null) { + onItemTouchCallbackListener.beforeMove(fromPos); + } + } } @Override @@ -545,6 +568,8 @@ public class ListNode extends SuperNode implements IDoricScrollabl private interface OnItemTouchCallbackListener { void onSwiped(int adapterPosition); + void beforeMove(int fromPos); + boolean onMove(int srcPosition, int targetPosition); void onMoved(int fromPos, int toPos);