use of com.taobao.weex.ui.IWXRenderTask in project weex-example by KalicyZhou.
the class WXDomStatement method addEvent.
/**
* Create a command object for adding a default event listener to the corresponding {@link
* WXDomObject} and put the command object in the queue.
* When the event is triggered, the eventListener will call {@link WXSDKManager#fireEvent(String, String, String)}
* , and the JS will handle all the operations from there.
*
* @param ref Reference of the dom.
* @param type the type of the event, this may be a plain event defined in
* {@link com.taobao.weex.common.Constants.Event} or a gesture defined in {@link com.taobao
* .weex.ui.view.gesture.WXGestureType}
*/
void addEvent(final String ref, final String type) {
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_ADDEVENT);
}
return;
}
domObject.addEvent(type);
mNormalTasks.add(new IWXRenderTask() {
@Override
public void execute() {
WXComponent comp = mWXRenderManager.getWXComponent(mInstanceId, ref);
if (comp != null) {
//sync dom change to component
comp.updateDom(domObject);
mWXRenderManager.addEvent(mInstanceId, ref, type);
}
}
@Override
public String toString() {
return "Add event";
}
});
mDirty = true;
if (instance != null) {
instance.commitUTStab(IWXUserTrackAdapter.DOM_MODULE, WXErrorCode.WX_SUCCESS);
}
}
use of com.taobao.weex.ui.IWXRenderTask in project weex-example by KalicyZhou.
the class WXDomStatement method addDomInternal.
/**
* Add DOM node.
* @param dom
* @param isRoot
* @param parentRef
* @param index
*/
private void addDomInternal(JSONObject dom, boolean isRoot, String parentRef, final int index) {
if (mDestroy) {
return;
}
WXSDKInstance instance = WXSDKManager.getInstance().getSDKInstance(mInstanceId);
if (instance == null) {
return;
}
WXErrorCode errCode = isRoot ? WXErrorCode.WX_ERR_DOM_CREATEBODY : WXErrorCode.WX_ERR_DOM_ADDELEMENT;
if (dom == null) {
instance.commitUTStab(IWXUserTrackAdapter.DOM_MODULE, errCode);
}
//only non-root has parent.
WXDomObject parent;
WXDomObject domObject = WXDomObject.parse(dom, instance);
if (domObject == null || mRegistry.containsKey(domObject.getRef())) {
if (WXEnvironment.isApkDebugable()) {
WXLogUtils.e("[WXDomStatement] " + (isRoot ? "createBody" : "addDom") + " error,DOM object is null or already registered!!");
}
instance.commitUTStab(IWXUserTrackAdapter.DOM_MODULE, errCode);
return;
}
if (isRoot) {
WXDomObject.prepareRoot(domObject, WXViewUtils.getWebPxByWidth(WXViewUtils.getWeexHeight(mInstanceId), WXSDKManager.getInstanceViewPortWidth(mInstanceId)), WXViewUtils.getWebPxByWidth(WXViewUtils.getWeexWidth(mInstanceId), WXSDKManager.getInstanceViewPortWidth(mInstanceId)));
} else if ((parent = mRegistry.get(parentRef)) == null) {
instance.commitUTStab(IWXUserTrackAdapter.DOM_MODULE, errCode);
return;
} else {
//non-root and parent exist
parent.add(domObject, index);
}
domObject.traverseTree(mAddDOMConsumer, ApplyStyleConsumer.getInstance());
//Create component in dom thread
WXComponent component = isRoot ? mWXRenderManager.createBodyOnDomThread(mInstanceId, domObject) : mWXRenderManager.createComponentOnDomThread(mInstanceId, domObject, parentRef, index);
if (component == null) {
instance.commitUTStab(IWXUserTrackAdapter.DOM_MODULE, errCode);
//stop redner, some fatal happened.
return;
}
AddDomInfo addDomInfo = new AddDomInfo();
addDomInfo.component = component;
mAddDom.put(domObject.getRef(), addDomInfo);
IWXRenderTask task = isRoot ? new CreateBodyTask(component) : new AddDOMTask(component, parentRef, index);
mNormalTasks.add(task);
addAnimationForDomTree(domObject);
mDirty = true;
instance.commitUTStab(IWXUserTrackAdapter.DOM_MODULE, WXErrorCode.WX_SUCCESS);
}
use of com.taobao.weex.ui.IWXRenderTask 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.ui.IWXRenderTask 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.ui.IWXRenderTask in project weex-example by KalicyZhou.
the class WXDomStatement method startAnimation.
void startAnimation(@NonNull final String ref, @NonNull String animation, @Nullable final String callBack) {
if (mDestroy) {
return;
}
WXDomObject domObject = mRegistry.get(ref);
if (domObject == null) {
return;
}
final WXAnimationBean animationBean = createAnimationBean(ref, animation);
if (animationBean != null) {
mNormalTasks.add(new IWXRenderTask() {
@Override
public void execute() {
mWXRenderManager.startAnimation(mInstanceId, ref, animationBean, callBack);
}
@Override
public String toString() {
return "startAnimationByCall";
}
});
mDirty = true;
}
}
Aggregations