Search in sources :

Example 6 with WXComponent

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);
}
Also used : WXComponent(com.taobao.weex.ui.component.WXComponent)

Example 7 with WXComponent

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);
}
Also used : Rect(android.graphics.Rect) WXComponent(com.taobao.weex.ui.component.WXComponent) HashMap(java.util.HashMap) WXDomObject(com.taobao.weex.dom.WXDomObject) JSONObject(com.alibaba.fastjson.JSONObject)

Example 8 with WXComponent

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);
    }
}
Also used : IWXRenderTask(com.taobao.weex.ui.IWXRenderTask) WXSDKInstance(com.taobao.weex.WXSDKInstance) WXComponent(com.taobao.weex.ui.component.WXComponent)

Example 9 with WXComponent

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);
}
Also used : WXErrorCode(com.taobao.weex.common.WXErrorCode) IWXRenderTask(com.taobao.weex.ui.IWXRenderTask) WXSDKInstance(com.taobao.weex.WXSDKInstance) WXComponent(com.taobao.weex.ui.component.WXComponent)

Example 10 with WXComponent

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;
}
Also used : WXComponent(com.taobao.weex.ui.component.WXComponent)

Aggregations

WXComponent (com.taobao.weex.ui.component.WXComponent)101 Point (android.graphics.Point)21 WXDomObject (com.taobao.weex.dom.WXDomObject)20 WXVContainer (com.taobao.weex.ui.component.WXVContainer)19 HashMap (java.util.HashMap)13 View (android.view.View)9 WXSDKInstanceTest (com.taobao.weex.WXSDKInstanceTest)9 WXRecyclerView (com.taobao.weex.ui.view.listview.WXRecyclerView)9 Map (java.util.Map)9 Test (org.junit.Test)9 ArrayMap (android.support.v4.util.ArrayMap)8 RecyclerView (android.support.v7.widget.RecyclerView)8 JSONObject (com.alibaba.fastjson.JSONObject)8 WXSDKInstance (com.taobao.weex.WXSDKInstance)8 ComponentTest (com.taobao.weex.ui.component.ComponentTest)8 WXDivTest (com.taobao.weex.ui.component.WXDivTest)8 Scrollable (com.taobao.weex.ui.component.Scrollable)6 WXBaseRefresh (com.taobao.weex.ui.component.WXBaseRefresh)6 WXHeaderTest (com.taobao.weex.ui.component.WXHeaderTest)6 AppearanceHelper (com.taobao.weex.ui.component.AppearanceHelper)5