feat:android render response time change

This commit is contained in:
刘涛 2021-02-24 14:53:28 +08:00 committed by osborn
parent 411c92f0f0
commit cc6355aea7

View File

@ -17,22 +17,10 @@ package pub.doric.plugin;
import android.app.Activity; import android.app.Activity;
import android.os.Build; import android.os.Build;
import android.os.Looper;
import android.os.MessageQueue;
import android.text.TextUtils; import android.text.TextUtils;
import android.util.Log; import android.util.Log;
import android.view.Choreographer;
import pub.doric.DoricContext; import android.view.View;
import pub.doric.async.AsyncResult;
import pub.doric.extension.bridge.DoricMethod;
import pub.doric.extension.bridge.DoricPlugin;
import pub.doric.extension.bridge.DoricPromise;
import pub.doric.shader.SuperNode;
import pub.doric.shader.ViewNode;
import pub.doric.utils.DoricMetaInfo;
import pub.doric.utils.DoricUtils;
import pub.doric.utils.ThreadMode;
import pub.doric.shader.RootNode;
import com.github.pengfeizhou.jscore.JSObject; import com.github.pengfeizhou.jscore.JSObject;
import com.github.pengfeizhou.jscore.JSValue; import com.github.pengfeizhou.jscore.JSValue;
@ -41,6 +29,18 @@ import com.github.pengfeizhou.jscore.JavaValue;
import java.lang.reflect.Method; import java.lang.reflect.Method;
import java.util.concurrent.Callable; import java.util.concurrent.Callable;
import pub.doric.DoricContext;
import pub.doric.async.AsyncResult;
import pub.doric.extension.bridge.DoricMethod;
import pub.doric.extension.bridge.DoricPlugin;
import pub.doric.extension.bridge.DoricPromise;
import pub.doric.shader.RootNode;
import pub.doric.shader.SuperNode;
import pub.doric.shader.ViewNode;
import pub.doric.utils.DoricMetaInfo;
import pub.doric.utils.DoricUtils;
import pub.doric.utils.ThreadMode;
/** /**
* @Description: com.github.penfeizhou.doric.plugin * @Description: com.github.penfeizhou.doric.plugin
* @Author: pengfei.zhou * @Author: pengfei.zhou
@ -64,21 +64,30 @@ public class ShaderPlugin extends DoricJavaPlugin {
} }
} }
String viewId = jsObject.getProperty("id").asString().value(); String viewId = jsObject.getProperty("id").asString().value();
RootNode rootNode = getDoricContext().getRootNode(); RootNode rootNode = getDoricContext().getRootNode();
ViewNode targetNode = rootNode;
if (TextUtils.isEmpty(rootNode.getId()) && "Root".equals(jsObject.getProperty("type").asString().value())) { if (TextUtils.isEmpty(rootNode.getId()) && "Root".equals(jsObject.getProperty("type").asString().value())) {
rootNode.setId(viewId); rootNode.setId(viewId);
rootNode.blend(jsObject.getProperty("props").asObject()); rootNode.blend(jsObject.getProperty("props").asObject());
} else { } else {
ViewNode viewNode = getDoricContext().targetViewNode(viewId); ViewNode viewNode = getDoricContext().targetViewNode(viewId);
if (viewNode != null) { if (viewNode != null) {
targetNode = viewNode;
viewNode.blend(jsObject.getProperty("props").asObject()); viewNode.blend(jsObject.getProperty("props").asObject());
} }
} }
Looper.myQueue().addIdleHandler(new MessageQueue.IdleHandler() { final View targetView = targetNode.getNodeView();
Choreographer.getInstance().postFrameCallback(new Choreographer.FrameCallback() {
@Override @Override
public boolean queueIdle() { public void doFrame(long frameTimeNanos) {
promise.resolve(); Choreographer.getInstance().removeFrameCallback(this);
return false; targetView.post(new Runnable() {
@Override
public void run() {
promise.resolve();
}
});
} }
}); });
return null; return null;