feat:adjust the inject timing of panel's initData
This commit is contained in:
@@ -17,6 +17,7 @@ package pub.doric;
|
||||
|
||||
import android.animation.AnimatorSet;
|
||||
import android.content.Context;
|
||||
import android.text.TextUtils;
|
||||
|
||||
import com.github.pengfeizhou.jscore.JSDecoder;
|
||||
import com.github.pengfeizhou.jscore.JSONBuilder;
|
||||
@@ -114,17 +115,24 @@ public class DoricContext {
|
||||
public static DoricContext create(Context context, String script, String source, String extra) {
|
||||
DoricContext doricContext = DoricContextManager.getInstance().createContext(context, script, source, extra);
|
||||
doricContext.script = script;
|
||||
doricContext.extra = extra;
|
||||
doricContext.init(extra);
|
||||
doricContext.callEntity(DoricConstant.DORIC_ENTITY_CREATE);
|
||||
return doricContext;
|
||||
}
|
||||
|
||||
public void init(float width, float height) {
|
||||
public void init(String initData) {
|
||||
this.extra = initData;
|
||||
if (!TextUtils.isEmpty(initData)) {
|
||||
callEntity(DoricConstant.DORIC_ENTITY_INIT, initData);
|
||||
}
|
||||
}
|
||||
|
||||
public void build(float width, float height) {
|
||||
this.initParams = new JSONBuilder()
|
||||
.put("width", width)
|
||||
.put("height", height)
|
||||
.toJSONObject();
|
||||
callEntity(DoricConstant.DORIC_ENTITY_INIT, this.initParams, extra);
|
||||
callEntity(DoricConstant.DORIC_ENTITY_BUILD, this.initParams);
|
||||
}
|
||||
|
||||
public AsyncResult<JSDecoder> callEntity(String methodName, Object... args) {
|
||||
@@ -186,8 +194,9 @@ public class DoricContext {
|
||||
this.script = script;
|
||||
this.mRootNode.setId("");
|
||||
getDriver().createContext(mContextId, script, source);
|
||||
init(this.extra);
|
||||
callEntity(DoricConstant.DORIC_ENTITY_CREATE);
|
||||
callEntity(DoricConstant.DORIC_ENTITY_INIT, this.initParams, extra);
|
||||
callEntity(DoricConstant.DORIC_ENTITY_BUILD, this.initParams);
|
||||
onShow();
|
||||
}
|
||||
|
||||
|
@@ -61,15 +61,15 @@ public class DoricPanel extends FrameLayout implements LifecycleObserver {
|
||||
|
||||
public void config(String script, String alias, String extra) {
|
||||
DoricContext doricContext = DoricContext.create(getContext(), script, alias, extra);
|
||||
doricContext.onShow();
|
||||
config(doricContext);
|
||||
doricContext.onShow();
|
||||
}
|
||||
|
||||
public void config(DoricContext doricContext) {
|
||||
mDoricContext = doricContext;
|
||||
mDoricContext.getRootNode().setRootView(this);
|
||||
if (getMeasuredWidth() != 0 && getMeasuredHeight() != 0) {
|
||||
mDoricContext.init(DoricUtils.px2dp(getMeasuredWidth()), DoricUtils.px2dp(getMeasuredHeight()));
|
||||
mDoricContext.build(DoricUtils.px2dp(getMeasuredWidth()), DoricUtils.px2dp(getMeasuredHeight()));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -95,7 +95,7 @@ public class DoricPanel extends FrameLayout implements LifecycleObserver {
|
||||
renderedWidth = w;
|
||||
renderedHeight = h;
|
||||
} else {
|
||||
mDoricContext.init(DoricUtils.px2dp(w), DoricUtils.px2dp(h));
|
||||
mDoricContext.build(DoricUtils.px2dp(w), DoricUtils.px2dp(h));
|
||||
renderedWidth = w;
|
||||
renderedHeight = h;
|
||||
}
|
||||
|
@@ -70,4 +70,5 @@ public class DoricConstant {
|
||||
public static final String DORIC_ENTITY_DESTROY = "__onDestroy__";
|
||||
public static final String DORIC_ENTITY_SHOW = "__onShow__";
|
||||
public static final String DORIC_ENTITY_HIDDEN = "__onHidden__";
|
||||
public static final String DORIC_ENTITY_BUILD = "__build__";
|
||||
}
|
||||
|
Reference in New Issue
Block a user