Search in sources :

Example 1 with WXSDKInstance

use of com.taobao.weex.WXSDKInstance in project weex-example by KalicyZhou.

the class WXRenderStatementTest method setUp.

@Before
public void setUp() throws Exception {
    PowerMockito.mockStatic(WXSoInstallMgrSdk.class);
    PowerMockito.mockStatic(TextUtils.class);
    PowerMockito.mockStatic(WXComponentFactory.class);
    PowerMockito.when(TextUtils.isEmpty("124")).thenReturn(true);
    PowerMockito.when(WXSoInstallMgrSdk.initSo(null, 1, null)).thenReturn(true);
    WXSDKInstance instance = Mockito.mock(WXSDKInstance.class);
    mWXRenderStatement = new WXRenderStatement(instance);
}
Also used : WXSDKInstance(com.taobao.weex.WXSDKInstance) Before(org.junit.Before)

Example 2 with WXSDKInstance

use of com.taobao.weex.WXSDKInstance in project weex-example by KalicyZhou.

the class WXTextTest method setUp.

@Before
public void setUp() throws Exception {
    WXEnvironment.sApplication = RuntimeEnvironment.application;
    WXSDKInstance instance = Mockito.mock(WXSDKInstance.class);
    Mockito.when(instance.getContext()).thenReturn(RuntimeEnvironment.application);
    mParentDomObj = Mockito.spy(new WXDomObject());
    Mockito.when(mParentDomObj.getPadding()).thenReturn(new Spacing());
    Mockito.when(mParentDomObj.getBorder()).thenReturn(new Spacing());
    Mockito.when(mParentDomObj.clone()).thenReturn(mParentDomObj);
    TestDomObject.setRef(mParentDomObj, WXDomObject.ROOT);
    mDomObject = Mockito.spy(new WXTextDomObject());
    TestDomObject.setRef(mDomObject, "1");
    mDomObject.addEvent(Constants.Event.CLICK);
    Mockito.when(mDomObject.clone()).thenReturn(mDomObject);
    Mockito.when(mDomObject.getPadding()).thenReturn(new Spacing());
    Mockito.when(mDomObject.getBorder()).thenReturn(new Spacing());
    Mockito.when(mDomObject.getMargin()).thenReturn(new Spacing());
    Mockito.when(mDomObject.getLayoutWidth()).thenReturn(100f);
    Mockito.when(mDomObject.getLayoutHeight()).thenReturn(100f);
    mParent = new WXDiv(instance, mParentDomObj, null);
    mParent.createView();
    mWXText = new WXText(instance, mDomObject, mParent);
    mWXText.bindHolder(new SimpleComponentHolder(WXText.class));
    assertNotNull(instance.getContext());
}
Also used : WXSDKInstance(com.taobao.weex.WXSDKInstance) WXDomObject(com.taobao.weex.dom.WXDomObject) WXTextDomObject(com.taobao.weex.dom.WXTextDomObject) SimpleComponentHolder(com.taobao.weex.ui.SimpleComponentHolder) Spacing(com.taobao.weex.dom.flex.Spacing) Before(org.junit.Before)

Example 3 with WXSDKInstance

use of com.taobao.weex.WXSDKInstance in project weex-example by KalicyZhou.

the class WXDivTest method setUp.

@Before
public void setUp() throws Exception {
    WXSDKInstance instance = Mockito.mock(WXSDKInstance.class);
    Mockito.when(instance.getContext()).thenReturn(RuntimeEnvironment.application);
    WXDomObject divDom = new WXDomObject();
    WXDomObject spy = Mockito.spy(divDom);
    Mockito.when(spy.getPadding()).thenReturn(new Spacing());
    Mockito.when(spy.getEvents()).thenReturn(new WXEvent());
    Mockito.when(spy.clone()).thenReturn(divDom);
    TestDomObject.setRef(divDom, "1");
    mWXDiv = new WXDiv(instance, divDom, null);
    mWXDiv.initView();
}
Also used : WXSDKInstance(com.taobao.weex.WXSDKInstance) WXDomObject(com.taobao.weex.dom.WXDomObject) WXEvent(com.taobao.weex.dom.WXEvent) Spacing(com.taobao.weex.dom.flex.Spacing) Before(org.junit.Before)

Example 4 with WXSDKInstance

use of com.taobao.weex.WXSDKInstance 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 5 with WXSDKInstance

use of com.taobao.weex.WXSDKInstance 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)

Aggregations

WXSDKInstance (com.taobao.weex.WXSDKInstance)30 IWXRenderTask (com.taobao.weex.ui.IWXRenderTask)10 WXDomObject (com.taobao.weex.dom.WXDomObject)3 Spacing (com.taobao.weex.dom.flex.Spacing)3 WXComponent (com.taobao.weex.ui.component.WXComponent)3 Before (org.junit.Before)3 Rect (android.graphics.Rect)2 RenderContainer (com.taobao.weex.RenderContainer)2 Activity (android.app.Activity)1 Uri (android.net.Uri)1 ArrayMap (android.support.v4.util.ArrayMap)1 ViewGroup (android.view.ViewGroup)1 JSONObject (com.alibaba.fastjson.JSONObject)1 WXHttpTask (com.alibaba.weex.https.WXHttpTask)1 WXRequestListener (com.alibaba.weex.https.WXRequestListener)1 WXSDKInstanceTest (com.taobao.weex.WXSDKInstanceTest)1 IWXJSExceptionAdapter (com.taobao.weex.adapter.IWXJSExceptionAdapter)1 IWXUserTrackAdapter (com.taobao.weex.adapter.IWXUserTrackAdapter)1 WXErrorCode (com.taobao.weex.common.WXErrorCode)1 WXException (com.taobao.weex.common.WXException)1