use of com.taobao.weex.ui.component.WXComponent in project weex-example by KalicyZhou.
the class WXRenderStatement method addEvent.
/**
* @see com.taobao.weex.dom.WXDomStatement#addEvent(String, String)
*/
void addEvent(String ref, String type) {
WXComponent component = mRegistry.get(ref);
if (component == null) {
return;
}
component.addEvent(type);
}
use of com.taobao.weex.ui.component.WXComponent in project weex-example by KalicyZhou.
the class WXRenderStatement method getComponentSize.
public void getComponentSize(String ref, JSCallback callback) {
WXComponent component = mRegistry.get(ref);
Map<String, Object> options = new HashMap<>();
if (component != null) {
Map<String, String> size = new HashMap<>();
Rect sizes = component.getComponentSize();
size.put("width", String.valueOf(WXViewUtils.getWebPxByWidth(sizes.width(), mWXSDKInstance.getViewPortWidth())));
size.put("height", String.valueOf(WXViewUtils.getWebPxByWidth(sizes.height(), mWXSDKInstance.getViewPortWidth())));
size.put("bottom", String.valueOf(WXViewUtils.getWebPxByWidth(sizes.bottom, mWXSDKInstance.getViewPortWidth())));
size.put("left", String.valueOf(WXViewUtils.getWebPxByWidth(sizes.left, mWXSDKInstance.getViewPortWidth())));
size.put("right", String.valueOf(WXViewUtils.getWebPxByWidth(sizes.right, mWXSDKInstance.getViewPortWidth())));
size.put("top", String.valueOf(WXViewUtils.getWebPxByWidth(sizes.top, mWXSDKInstance.getViewPortWidth())));
options.put("size", size);
options.put("result", true);
} else {
options.put("errMsg", "Component does not exist");
}
callback.invoke(options);
}
use of com.taobao.weex.ui.component.WXComponent 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.component.WXComponent 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.component.WXComponent in project weex-example by KalicyZhou.
the class ExternalLoaderComponentHolder method createInstance.
@Override
public synchronized WXComponent createInstance(WXSDKInstance instance, WXDomObject node, WXVContainer parent) throws IllegalAccessException, InvocationTargetException, InstantiationException {
if (mClass == null) {
mClass = mClzGetter.getExternalComponentClass(mType, instance);
}
ComponentCreator creator = new SimpleComponentHolder.ClazzComponentCreator(mClass);
WXComponent component = creator.createInstance(instance, node, parent);
component.bindHolder(this);
return component;
}
Aggregations