feat:add getLocationOnScreen

This commit is contained in:
pengfei.zhou 2019-12-12 17:32:16 +08:00
parent c55da9c640
commit a8397c0bf2

View File

@ -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<T extends View> 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<T extends View> 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<T extends View> 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();
}
}