android: optimize hot reload operation which causes render error

This commit is contained in:
pengfei.zhou 2022-08-01 14:42:55 +08:00 committed by osborn
parent d391cb8348
commit 2f9afac7bd
2 changed files with 10 additions and 2 deletions

View File

@ -245,16 +245,20 @@ public class DoricContext {
public void reload(String script) { public void reload(String script) {
retainedJavaValues.clear(); retainedJavaValues.clear();
getDriver().destroyContext(getContextId()); IDoricDriver driver = getDriver();
driver.destroyContext(getContextId()).synchronous().get();
for (DoricJavaPlugin javaPlugin : mPluginMap.values()) { for (DoricJavaPlugin javaPlugin : mPluginMap.values()) {
javaPlugin.onTearDown(); javaPlugin.onTearDown();
} }
mPluginMap.clear(); mPluginMap.clear();
if (driver instanceof DoricNativeDriver) {
((DoricNativeDriver) driver).clearPendingJobs();
}
this.script = script; this.script = script;
this.mRootNode.setId(""); this.mRootNode.setId("");
this.mRootNode.clearSubModel(); this.mRootNode.clearSubModel();
this.mRootNode.getView().removeAllViews(); this.mRootNode.getView().removeAllViews();
getDriver().createContext(mContextId, script, source); driver.createContext(mContextId, script, source);
init(this.extra); init(this.extra);
callEntity(DoricConstant.DORIC_ENTITY_CREATE); callEntity(DoricConstant.DORIC_ENTITY_CREATE);
callEntity(DoricConstant.DORIC_ENTITY_BUILD, this.initParams); callEntity(DoricConstant.DORIC_ENTITY_BUILD, this.initParams);

View File

@ -232,4 +232,8 @@ public class DoricNativeDriver implements IDoricDriver {
public DoricJSEngine getDoricJSEngine() { public DoricJSEngine getDoricJSEngine() {
return doricJSEngine; return doricJSEngine;
} }
public void clearPendingJobs() {
this.mUIHandler.removeCallbacksAndMessages(null);
}
} }