use of com.taobao.weex.WXSDKInstance in project weex-example by KalicyZhou.
the class WXDomStatement method moveDom.
/**
* Create a command object for moving the specific {@link WXDomObject} to a new parent.
* If any of the following situation is met,
* <ul>
* <li> dom to be moved is null </li>
* <li> dom's parent is null </li>
* <li> new parent is null </li>
* <li> parent is under {@link CSSNode#hasNewLayout()} </li>
* </ul>
* this method will return. Otherwise, put the command object in the queue.
* @param ref Reference of the dom to be moved.
* @param parentRef Reference of the new parent DOM node
* @param index the index of the dom to be inserted in the new parent.
*/
void moveDom(final String ref, final String parentRef, int index) {
if (mDestroy) {
return;
}
WXSDKInstance instance = WXSDKManager.getInstance().getSDKInstance(mInstanceId);
WXDomObject domObject = mRegistry.get(ref);
WXDomObject parentObject = mRegistry.get(parentRef);
if (domObject == null || domObject.parent == null || parentObject == null || parentObject.hasNewLayout()) {
if (instance != null) {
instance.commitUTStab(IWXUserTrackAdapter.DOM_MODULE, WXErrorCode.WX_ERR_DOM_MOVEELEMENT);
}
return;
}
if (domObject.parent.equals(parentObject)) {
if (parentObject.index(domObject) == index) {
return;
} else if (domObject.parent.index(domObject) < index) {
index = index - 1;
}
}
final int newIndex = index;
domObject.parent.remove(domObject);
parentObject.add(domObject, newIndex);
mNormalTasks.add(new IWXRenderTask() {
@Override
public void execute() {
mWXRenderManager.moveComponent(mInstanceId, ref, parentRef, newIndex);
}
@Override
public String toString() {
return "moveDom";
}
});
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 removeDom.
/**
* Create a command object for removing the specified {@link WXDomObject}.
* If the domObject is null or its parent is null, this method returns directly.
* Otherwise, put the command object in the queue.
* @param ref Reference of the dom.
*/
void removeDom(final String ref) {
if (mDestroy) {
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_REMOVEELEMENT);
}
return;
}
WXDomObject parent = domObject.parent;
if (parent == null) {
if (instance != null) {
instance.commitUTStab(IWXUserTrackAdapter.DOM_MODULE, WXErrorCode.WX_ERR_DOM_REMOVEELEMENT);
}
return;
}
domObject.traverseTree(new WXDomObject.Consumer() {
@Override
public void accept(WXDomObject dom) {
mRegistry.remove(dom.getRef());
}
});
parent.remove(domObject);
mRegistry.remove(ref);
mNormalTasks.add(new IWXRenderTask() {
@Override
public void execute() {
mWXRenderManager.removeComponent(mInstanceId, ref);
}
@Override
public String toString() {
return "removeDom";
}
});
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 refreshFinish.
/**
* Create a command object for notifying {@link WXRenderManager} that the process of refreshing
* given view is finished, and put the command object in the queue.
*/
void refreshFinish() {
if (mDestroy) {
return;
}
final WXDomObject root = mRegistry.get(WXDomObject.ROOT);
mNormalTasks.add(new IWXRenderTask() {
@Override
public void execute() {
int realWidth = (int) root.getLayoutWidth();
int realHeight = (int) root.getLayoutHeight();
mWXRenderManager.refreshFinish(mInstanceId, realWidth, realHeight);
}
@Override
public String toString() {
return "refreshFinish";
}
});
mDirty = true;
WXSDKInstance instance = WXSDKManager.getInstance().getSDKInstance(mInstanceId);
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 WXModuleManager method callModuleMethod.
static Object callModuleMethod(final String instanceId, String moduleStr, String methodStr, JSONArray args) {
ModuleFactory factory = sModuleFactoryMap.get(moduleStr);
if (factory == null) {
WXLogUtils.e("[WXModuleManager] module factory not found.");
return null;
}
final WXModule wxModule = findModule(instanceId, moduleStr, factory);
if (wxModule == null) {
return null;
}
WXSDKInstance instance = WXSDKManager.getInstance().getSDKInstance(instanceId);
wxModule.mWXSDKInstance = instance;
final Invoker invoker = factory.getMethodInvoker(methodStr);
try {
return instance.getNativeInvokeHelper().invoke(wxModule, invoker, args);
} catch (Exception e) {
WXLogUtils.e("callModuleMethod >>> invoke module:" + moduleStr + ", method:" + methodStr + " failed. ", e);
return null;
} finally {
if (wxModule instanceof WXDomModule || wxModule instanceof WXTimerModule) {
wxModule.mWXSDKInstance = null;
}
}
}
use of com.taobao.weex.WXSDKInstance in project weex-example by KalicyZhou.
the class WXBridge method callAddElement.
/**
* JSF render Node by callAddElement
*/
public int callAddElement(String instanceId, String ref, String dom, String index, String callback) {
long start = System.currentTimeMillis();
WXSDKInstance instance = WXSDKManager.getInstance().getSDKInstance(instanceId);
if (instance != null) {
instance.firstScreenCreateInstanceTime(start);
}
int errorCode = IWXBridge.INSTANCE_RENDERING;
try {
errorCode = WXBridgeManager.getInstance().callAddElement(instanceId, ref, dom, index, callback);
} catch (Throwable e) {
//catch everything during call native.
if (WXEnvironment.isApkDebugable()) {
e.printStackTrace();
WXLogUtils.e(TAG, "callNative throw error:" + e.getMessage());
}
}
if (instance != null) {
instance.callNativeTime(System.currentTimeMillis() - start);
}
if (WXEnvironment.isApkDebugable()) {
if (errorCode == IWXBridge.DESTROY_INSTANCE) {
WXLogUtils.w("destroyInstance :" + instanceId + " JSF must stop callNative");
}
}
return errorCode;
}
Aggregations