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(); + } }