complete Android & iOS with same logic

This commit is contained in:
王劲鹏
2020-01-03 18:06:57 +08:00
committed by osborn
parent ece2e0cac2
commit e06b305eb8
6 changed files with 110 additions and 20 deletions

View File

@@ -9,6 +9,7 @@ import com.github.pengfeizhou.jscore.JSValue;
import pub.doric.DoricContext;
import pub.doric.extension.bridge.DoricPlugin;
import pub.doric.utils.DoricUtils;
@DoricPlugin(name = "Draggable")
public class DraggableNode extends StackNode {
@@ -52,9 +53,6 @@ public class DraggableNode extends StackNode {
int x = (int) event.getX();
int y = (int) event.getY();
int rawX = (int) event.getRawX();
int rawY = (int) event.getRawY();
switch (event.getAction()) {
case MotionEvent.ACTION_DOWN:
lastX = x;
@@ -63,13 +61,11 @@ public class DraggableNode extends StackNode {
case MotionEvent.ACTION_MOVE:
int offsetX = x - lastX;
int offsetY = y - lastY;
layout(getLeft() + offsetX, getTop() + offsetY, getRight() + offsetX, getBottom() + offsetY);
callJSResponse(onDrag, DoricUtils.px2dp(offsetX), DoricUtils.px2dp(offsetY));
break;
case MotionEvent.ACTION_UP:
break;
}
callJSResponse(onDrag, rawX - x, rawY - y);
return true;
}
}

View File

@@ -191,11 +191,11 @@ public class DoricUtils {
return getScreenHeight(null);
}
public static float px2dp(int pxValue) {
public static float px2dp(float pxValue) {
return px2dp(null, pxValue);
}
public static float px2dp(Context context, int pxValue) {
public static float px2dp(Context context, float pxValue) {
if (context == null) {
context = Doric.application();
}