use of com.taobao.weex.WXSDKInstance in project weex-example by KalicyZhou.
the class WXBridgeManager method commitJSBridgeAlarmMonitor.
public void commitJSBridgeAlarmMonitor(String instanceId, WXErrorCode errCode, String errMsg) {
WXSDKInstance instance = WXSDKManager.getInstance().getSDKInstance(instanceId);
IWXUserTrackAdapter adapter = WXSDKManager.getInstance().getIWXUserTrackAdapter();
if (instance == null || adapter == null || errCode == null) {
return;
}
WXPerformance performance = new WXPerformance();
performance.args = instance.getBundleUrl();
performance.errCode = errCode.getErrorCode();
if (errCode != WXErrorCode.WX_SUCCESS) {
performance.appendErrMsg(TextUtils.isEmpty(errMsg) ? errCode.getErrorMsg() : errMsg);
WXLogUtils.e("wx_monitor", performance.toString());
}
adapter.commit(WXEnvironment.getApplication(), null, IWXUserTrackAdapter.JS_BRIDGE, performance, instance.getUserTrackParams());
}
use of com.taobao.weex.WXSDKInstance in project weex-example by KalicyZhou.
the class WXBridgeManager method invokeRefreshInstance.
private void invokeRefreshInstance(String instanceId, WXRefreshData refreshData) {
try {
if (!isJSFrameworkInit()) {
WXSDKInstance instance = WXSDKManager.getInstance().getSDKInstance(instanceId);
if (instance != null) {
instance.onRenderError(WXRenderErrorCode.WX_CREATE_INSTANCE_ERROR, "createInstance failed!");
}
String err = "[WXBridgeManager] invokeRefreshInstance: framework.js uninitialized.";
commitJSBridgeAlarmMonitor(instanceId, WXErrorCode.WX_ERR_INVOKE_NATIVE, err);
WXLogUtils.e(err);
return;
}
long start = System.currentTimeMillis();
if (WXEnvironment.isApkDebugable()) {
WXLogUtils.d("refreshInstance >>>> instanceId:" + instanceId + ", data:" + refreshData.data + ", isDirty:" + refreshData.isDirty);
}
if (refreshData.isDirty) {
return;
}
WXJSObject instanceIdObj = new WXJSObject(WXJSObject.String, instanceId);
WXJSObject dataObj = new WXJSObject(WXJSObject.JSON, refreshData.data == null ? "{}" : refreshData.data);
WXJSObject[] args = { instanceIdObj, dataObj };
invokeExecJS(instanceId, null, METHOD_REFRESH_INSTANCE, args);
WXLogUtils.renderPerformanceLog("invokeRefreshInstance", System.currentTimeMillis() - start);
} catch (Throwable e) {
String err = "[WXBridgeManager] invokeRefreshInstance " + e.getCause();
commitJSBridgeAlarmMonitor(instanceId, WXErrorCode.WX_ERR_INVOKE_NATIVE, err);
WXLogUtils.e(err);
}
}
use of com.taobao.weex.WXSDKInstance in project weex-example by KalicyZhou.
the class WXBridgeManager method createInstance.
/**
* Create instance.
*/
public void createInstance(final String instanceId, final String template, final Map<String, Object> options, final String data) {
final WXSDKInstance instance = WXSDKManager.getInstance().getSDKInstance(instanceId);
if (instance == null) {
WXLogUtils.e("WXBridgeManager", "createInstance failed, SDKInstance is not exist");
return;
}
if (TextUtils.isEmpty(instanceId) || TextUtils.isEmpty(template) || mJSHandler == null) {
instance.onRenderError(WXRenderErrorCode.WX_CREATE_INSTANCE_ERROR, "createInstance fail!");
return;
}
WXModuleManager.createDomModule(instance);
post(new Runnable() {
@Override
public void run() {
long start = System.currentTimeMillis();
invokeCreateInstance(instance, template, options, data);
final long totalTime = System.currentTimeMillis() - start;
WXSDKManager.getInstance().postOnUiThread(new Runnable() {
@Override
public void run() {
instance.createInstanceFinished(totalTime);
}
}, 0);
}
}, instanceId);
}
use of com.taobao.weex.WXSDKInstance in project weex-example by KalicyZhou.
the class WXDomStatement method updateStyle.
/**
* Update styles according to the given style. Then creating a
* command object for updating corresponding view and put the command object in the queue.
* @param ref Reference of the dom.
* @param style the new style. This style is only a part of the full style, and will be merged
* into styles
* @param byPesudo updateStyle by pesduo class
* @see #updateAttrs(String, JSONObject)
*/
void updateStyle(String ref, JSONObject style, boolean byPesudo) {
if (mDestroy || style == null) {
return;
}
WXSDKInstance instance = WXSDKManager.getInstance().getSDKInstance(mInstanceId);
WXDomObject domObject = mRegistry.get(ref);
if (domObject == null) {
if (instance != null) {
instance.commitUTStab(IWXUserTrackAdapter.DOM_MODULE, WXErrorCode.WX_ERR_DOM_UPDATESTYLE);
}
return;
}
Map<String, Object> animationMap = new ArrayMap<>(2);
animationMap.put(WXDomObject.TRANSFORM, style.remove(WXDomObject.TRANSFORM));
animationMap.put(WXDomObject.TRANSFORM_ORIGIN, style.remove(WXDomObject.TRANSFORM_ORIGIN));
animations.add(new Pair<>(ref, animationMap));
if (!style.isEmpty()) {
domObject.updateStyle(style, byPesudo);
domObject.traverseTree(ApplyStyleConsumer.getInstance());
updateStyle(domObject, style);
}
mDirty = true;
if (instance != null) {
instance.commitUTStab(IWXUserTrackAdapter.DOM_MODULE, WXErrorCode.WX_SUCCESS);
}
}
use of com.taobao.weex.WXSDKInstance in project weex-example by KalicyZhou.
the class WXDomStatement method updateAttrs.
/**
* Update the attributes according to the given attribute. Then creating a
* command object for updating corresponding view and put the command object in the queue.
* @param ref Reference of the dom.
* @param attrs the new style. This style is only a part of the full attribute set, and will be
* merged into attributes
* @see #updateStyle(String, JSONObject)
*/
void updateAttrs(String ref, final JSONObject attrs) {
if (mDestroy) {
return;
}
WXSDKInstance instance = WXSDKManager.getInstance().getSDKInstance(mInstanceId);
final WXDomObject domObject = mRegistry.get(ref);
if (domObject == null) {
if (instance != null) {
instance.commitUTStab(IWXUserTrackAdapter.DOM_MODULE, WXErrorCode.WX_ERR_DOM_UPDATEATTRS);
}
return;
}
domObject.updateAttr(attrs);
mNormalTasks.add(new IWXRenderTask() {
@Override
public void execute() {
mWXRenderManager.updateAttrs(mInstanceId, domObject.getRef(), attrs);
}
@Override
public String toString() {
return "updateAttr";
}
});
mDirty = true;
if (instance != null) {
instance.commitUTStab(IWXUserTrackAdapter.DOM_MODULE, WXErrorCode.WX_SUCCESS);
}
}
Aggregations