Search in sources :

Example 21 with WXSDKInstance

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

the class WXDivTest method testAddChild.

@Test
public void testAddChild() {
    WXSDKInstance instance = Mockito.mock(WXSDKInstance.class);
    Mockito.when(instance.getContext()).thenReturn(RuntimeEnvironment.application);
    WXDomObject testDom = Mockito.mock(WXDomObject.class);
    Mockito.when(testDom.getPadding()).thenReturn(new Spacing());
    Mockito.when(testDom.clone()).thenReturn(testDom);
    TestDomObject.setRef(testDom, "2");
    WXText child1 = new WXText(instance, testDom, mWXDiv);
    child1.initView();
    mWXDiv.addChild(child1, 0);
    assertEquals(1, mWXDiv.childCount());
    WXDomObject testDom2 = Mockito.spy(new WXDomObject());
    Mockito.when(testDom2.getPadding()).thenReturn(new Spacing());
    Mockito.when(testDom2.clone()).thenReturn(testDom2);
    TestDomObject.setRef(testDom2, "3");
    child2 = new WXText(instance, testDom2, mWXDiv);
    child2.initView();
    mWXDiv.addChild(child2, -1);
    assertEquals(2, mWXDiv.childCount());
    assertEquals(child2, mWXDiv.getChild(1));
    WXDomObject testDom3 = Mockito.mock(WXDomObject.class);
    Mockito.when(testDom3.getPadding()).thenReturn(new Spacing());
    Mockito.when(testDom3.clone()).thenReturn(testDom3);
    TestDomObject.setRef(testDom3, "4");
    WXText child3 = new WXText(instance, testDom3, mWXDiv);
    child3.initView();
    mWXDiv.addChild(child3, 1);
    assertEquals(3, mWXDiv.childCount());
    assertEquals(child3, mWXDiv.getChild(1));
}
Also used : WXSDKInstance(com.taobao.weex.WXSDKInstance) WXDomObject(com.taobao.weex.dom.WXDomObject) Spacing(com.taobao.weex.dom.flex.Spacing) Test(org.junit.Test) WXSDKInstanceTest(com.taobao.weex.WXSDKInstanceTest)

Example 22 with WXSDKInstance

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

the class WXBridge method callNative.

public int callNative(String instanceId, String tasks, 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().callNative(instanceId, tasks, callback);
    } catch (Throwable e) {
        //catch everything during call native.
        if (WXEnvironment.isApkDebugable()) {
            WXLogUtils.e(TAG, "callNative throw exception:" + 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;
}
Also used : WXSDKInstance(com.taobao.weex.WXSDKInstance)

Example 23 with WXSDKInstance

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

the class WXDomStatement method updateFinish.

/**
   * Create a command object for notifying {@link WXRenderManager} that the process of update
   * given view is finished, and put the command object in the queue.
   */
void updateFinish() {
    if (mDestroy) {
        return;
    }
    mNormalTasks.add(new IWXRenderTask() {

        @Override
        public void execute() {
            mWXRenderManager.updateFinish(mInstanceId);
        }

        @Override
        public String toString() {
            return "updateFinish";
        }
    });
    WXSDKInstance instance = WXSDKManager.getInstance().getSDKInstance(mInstanceId);
    if (instance != null) {
        instance.commitUTStab(IWXUserTrackAdapter.DOM_MODULE, WXErrorCode.WX_SUCCESS);
    }
}
Also used : IWXRenderTask(com.taobao.weex.ui.IWXRenderTask) WXSDKInstance(com.taobao.weex.WXSDKInstance)

Example 24 with WXSDKInstance

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

the class WXDomStatement method scrollToDom.

/**
   * Create a command object for scroll the given view to the specified position.
   * @param ref Reference of the dom.
   * @param options the specified position
   */
void scrollToDom(final String ref, final JSONObject options) {
    if (mDestroy) {
        return;
    }
    WXSDKInstance instance = WXSDKManager.getInstance().getSDKInstance(mInstanceId);
    mNormalTasks.add(new IWXRenderTask() {

        @Override
        public void execute() {
            mWXRenderManager.scrollToComponent(mInstanceId, ref, options);
        }

        @Override
        public String toString() {
            return "scrollToPosition";
        }
    });
    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)

Example 25 with WXSDKInstance

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

the class WXDomStatement method removeEvent.

/**
   * Create a command object for removing the event listener of the corresponding {@link
   * WXDomObject} and put the command event in the queue.
   * @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 removeEvent(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_REMOVEEVENT);
        }
        return;
    }
    domObject.removeEvent(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.removeEvent(mInstanceId, ref, type);
            }
        }

        @Override
        public String toString() {
            return "removeEvent";
        }
    });
    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)

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