From a8397c0bf28bc21cb8b1fe5f4794ad96b22bfadc Mon Sep 17 00:00:00 2001 From: "pengfei.zhou" Date: Thu, 12 Dec 2019 17:32:16 +0800 Subject: [PATCH] feat:add getLocationOnScreen --- .../main/java/pub/doric/shader/ViewNode.java | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) diff --git a/doric/src/main/java/pub/doric/shader/ViewNode.java b/doric/src/main/java/pub/doric/shader/ViewNode.java index 3e0f1aa1..499f8216 100644 --- a/doric/src/main/java/pub/doric/shader/ViewNode.java +++ b/doric/src/main/java/pub/doric/shader/ViewNode.java @@ -37,6 +37,7 @@ import androidx.annotation.NonNull; import androidx.interpolator.view.animation.FastOutSlowInInterpolator; import androidx.interpolator.view.animation.LinearOutSlowInInterpolator; +import pub.doric.Doric; import pub.doric.DoricContext; import pub.doric.DoricRegistry; import pub.doric.async.AsyncResult; @@ -55,6 +56,8 @@ import com.github.pengfeizhou.jscore.JSObject; import com.github.pengfeizhou.jscore.JSValue; import com.github.pengfeizhou.jscore.JavaValue; +import org.json.JSONObject; + import java.util.LinkedList; /** @@ -501,7 +504,7 @@ public abstract class ViewNode extends DoricContextHolder { if (mLayoutParams.width >= 0) { return DoricUtils.px2dp(mLayoutParams.width); } else { - return mView.getMeasuredWidth(); + return DoricUtils.px2dp(mView.getMeasuredWidth()); } } @@ -510,7 +513,7 @@ public abstract class ViewNode extends DoricContextHolder { if (mLayoutParams.width >= 0) { return DoricUtils.px2dp(mLayoutParams.height); } else { - return mView.getMeasuredHeight(); + return DoricUtils.px2dp(mView.getMeasuredHeight()); } } @@ -849,4 +852,14 @@ public abstract class ViewNode extends DoricContextHolder { return 0; } } + + @DoricMethod + public JSONObject getLocationOnScreen() { + int[] position = new int[2]; + getNodeView().getLocationOnScreen(position); + return new JSONBuilder() + .put("x", DoricUtils.px2dp(position[0])) + .put("y", DoricUtils.px2dp(position[1])) + .toJSONObject(); + } }