Android: implement beforeDragging callback
This commit is contained in:
parent
86e5e2422f
commit
5071dfbfe5
@ -15,6 +15,8 @@
|
|||||||
*/
|
*/
|
||||||
package pub.doric.shader.list;
|
package pub.doric.shader.list;
|
||||||
|
|
||||||
|
import static androidx.recyclerview.widget.ItemTouchHelper.ACTION_STATE_DRAG;
|
||||||
|
|
||||||
import android.annotation.SuppressLint;
|
import android.annotation.SuppressLint;
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
import android.text.TextUtils;
|
import android.text.TextUtils;
|
||||||
@ -87,6 +89,13 @@ public class ListNode extends SuperNode<RecyclerView> implements IDoricScrollabl
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void beforeMove(int fromPos) {
|
||||||
|
if (!TextUtils.isEmpty(beforeDraggingFuncId)) {
|
||||||
|
callJSResponse(beforeDraggingFuncId, fromPos);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean onMove(int srcPosition, int targetPosition) {
|
public boolean onMove(int srcPosition, int targetPosition) {
|
||||||
String srcValue = itemValues.valueAt(srcPosition);
|
String srcValue = itemValues.valueAt(srcPosition);
|
||||||
@ -109,6 +118,7 @@ public class ListNode extends SuperNode<RecyclerView> implements IDoricScrollabl
|
|||||||
}
|
}
|
||||||
);
|
);
|
||||||
|
|
||||||
|
private String beforeDraggingFuncId;
|
||||||
private String onDraggingFuncId;
|
private String onDraggingFuncId;
|
||||||
private String onDraggedFuncId;
|
private String onDraggedFuncId;
|
||||||
|
|
||||||
@ -309,6 +319,12 @@ public class ListNode extends SuperNode<RecyclerView> implements IDoricScrollabl
|
|||||||
boolean canDrag = prop.asBoolean().value();
|
boolean canDrag = prop.asBoolean().value();
|
||||||
doricItemTouchHelperCallback.setDragEnable(canDrag);
|
doricItemTouchHelperCallback.setDragEnable(canDrag);
|
||||||
break;
|
break;
|
||||||
|
case "beforeDragging":
|
||||||
|
if (!prop.isString()) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
this.beforeDraggingFuncId = prop.asString().value();
|
||||||
|
break;
|
||||||
case "onDragging":
|
case "onDragging":
|
||||||
if (!prop.isString()) {
|
if (!prop.isString()) {
|
||||||
return;
|
return;
|
||||||
@ -434,8 +450,9 @@ public class ListNode extends SuperNode<RecyclerView> implements IDoricScrollabl
|
|||||||
onScrollFuncId = null;
|
onScrollFuncId = null;
|
||||||
onScrollEndFuncId = null;
|
onScrollEndFuncId = null;
|
||||||
renderItemFuncId = null;
|
renderItemFuncId = null;
|
||||||
onDraggedFuncId = null;
|
beforeDraggingFuncId = null;
|
||||||
onDraggingFuncId = null;
|
onDraggingFuncId = null;
|
||||||
|
onDraggedFuncId = null;
|
||||||
}
|
}
|
||||||
|
|
||||||
private static class DoricItemTouchHelper extends ItemTouchHelper {
|
private static class DoricItemTouchHelper extends ItemTouchHelper {
|
||||||
@ -522,6 +539,12 @@ public class ListNode extends SuperNode<RecyclerView> implements IDoricScrollabl
|
|||||||
if (viewHolder != null) {
|
if (viewHolder != null) {
|
||||||
fromPos = viewHolder.getAdapterPosition();
|
fromPos = viewHolder.getAdapterPosition();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (actionState == ACTION_STATE_DRAG) {
|
||||||
|
if (onItemTouchCallbackListener != null) {
|
||||||
|
onItemTouchCallbackListener.beforeMove(fromPos);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@ -545,6 +568,8 @@ public class ListNode extends SuperNode<RecyclerView> implements IDoricScrollabl
|
|||||||
private interface OnItemTouchCallbackListener {
|
private interface OnItemTouchCallbackListener {
|
||||||
void onSwiped(int adapterPosition);
|
void onSwiped(int adapterPosition);
|
||||||
|
|
||||||
|
void beforeMove(int fromPos);
|
||||||
|
|
||||||
boolean onMove(int srcPosition, int targetPosition);
|
boolean onMove(int srcPosition, int targetPosition);
|
||||||
|
|
||||||
void onMoved(int fromPos, int toPos);
|
void onMoved(int fromPos, int toPos);
|
||||||
|
Reference in New Issue
Block a user