Search in sources :

Example 6 with WXSDKInstance

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

Example 7 with WXSDKInstance

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

Example 8 with WXSDKInstance

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

the class WXDomStatement method refreshFinish.

/**
   * Create a command object for notifying {@link WXRenderManager} that the process of refreshing
   * given view is finished, and put the command object in the queue.
   */
void refreshFinish() {
    if (mDestroy) {
        return;
    }
    final WXDomObject root = mRegistry.get(WXDomObject.ROOT);
    mNormalTasks.add(new IWXRenderTask() {

        @Override
        public void execute() {
            int realWidth = (int) root.getLayoutWidth();
            int realHeight = (int) root.getLayoutHeight();
            mWXRenderManager.refreshFinish(mInstanceId, realWidth, realHeight);
        }

        @Override
        public String toString() {
            return "refreshFinish";
        }
    });
    mDirty = true;
    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 9 with WXSDKInstance

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

the class WXModuleManager method callModuleMethod.

static Object callModuleMethod(final String instanceId, String moduleStr, String methodStr, JSONArray args) {
    ModuleFactory factory = sModuleFactoryMap.get(moduleStr);
    if (factory == null) {
        WXLogUtils.e("[WXModuleManager] module factory not found.");
        return null;
    }
    final WXModule wxModule = findModule(instanceId, moduleStr, factory);
    if (wxModule == null) {
        return null;
    }
    WXSDKInstance instance = WXSDKManager.getInstance().getSDKInstance(instanceId);
    wxModule.mWXSDKInstance = instance;
    final Invoker invoker = factory.getMethodInvoker(methodStr);
    try {
        return instance.getNativeInvokeHelper().invoke(wxModule, invoker, args);
    } catch (Exception e) {
        WXLogUtils.e("callModuleMethod >>> invoke module:" + moduleStr + ", method:" + methodStr + " failed. ", e);
        return null;
    } finally {
        if (wxModule instanceof WXDomModule || wxModule instanceof WXTimerModule) {
            wxModule.mWXSDKInstance = null;
        }
    }
}
Also used : WXDomModule(com.taobao.weex.dom.WXDomModule) WXSDKInstance(com.taobao.weex.WXSDKInstance) WXTimerModule(com.taobao.weex.ui.module.WXTimerModule) WXModule(com.taobao.weex.common.WXModule) WXException(com.taobao.weex.common.WXException)

Example 10 with WXSDKInstance

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

the class WXBridge method callAddElement.

/**
   * JSF render Node by callAddElement
   */
public int callAddElement(String instanceId, String ref, String dom, String index, 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().callAddElement(instanceId, ref, dom, index, callback);
    } catch (Throwable e) {
        //catch everything during call native.
        if (WXEnvironment.isApkDebugable()) {
            e.printStackTrace();
            WXLogUtils.e(TAG, "callNative throw error:" + 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)

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