Search in sources :

Example 1 with EventResult

use of com.taobao.weex.bridge.EventResult in project incubator-weex by apache.

the class WXGesture method shouldBubbleTouchEvent.

/**
 * shouldBubbleEvent default true
 */
private boolean shouldBubbleTouchEvent(MotionEvent event) {
    if (component.containsEvent(STOP_PROPAGATION)) {
        if (shouldBubbleInterval > 0 && shouldBubbleCallRemainTimes > 0) {
            shouldBubbleCallRemainTimes--;
            return shouldBubbleResult;
        }
        Map<String, Object> eventMap = createFireEventParam(event, CUR_EVENT, null);
        eventMap.put("type", "touch");
        if (event.getAction() == MotionEvent.ACTION_DOWN) {
            eventMap.put("action", START);
        } else if (event.getAction() == MotionEvent.ACTION_CANCEL || event.getAction() == MotionEvent.ACTION_UP) {
            eventMap.put("action", END);
        } else {
            eventMap.put("action", MOVE);
        }
        EventResult result = component.fireEventWait(STOP_PROPAGATION, eventMap);
        if (result.isSuccess() && result.getResult() != null) {
            boolean stopPropagation = WXUtils.getBoolean(result.getResult(), !shouldBubbleResult);
            shouldBubbleResult = !stopPropagation;
        }
        shouldBubbleCallRemainTimes = shouldBubbleInterval;
        return shouldBubbleResult;
    }
    return true;
}
Also used : EventResult(com.taobao.weex.bridge.EventResult) JSONObject(com.alibaba.fastjson.JSONObject)

Example 2 with EventResult

use of com.taobao.weex.bridge.EventResult in project incubator-weex by apache.

the class Statements method doBindingAttrsEventAndRenderChildNode.

/**
 * bind attrs and doRender component child
 */
private static void doBindingAttrsEventAndRenderChildNode(WXComponent component, WXDomObject domObject, CellRenderContext context, List<WXComponent> updates) {
    WXAttr attr = component.getDomObject().getAttrs();
    /**
     * sub component supported, sub component new stack
     */
    ArrayStack stack = context.stack;
    if (attr.get(ELUtils.IS_COMPONENT_ROOT) != null && WXUtils.getBoolean(attr.get(ELUtils.IS_COMPONENT_ROOT), false)) {
        if (attr.get(ELUtils.COMPONENT_PROPS) != null && attr.get(ELUtils.COMPONENT_PROPS) instanceof JSONObject) {
            String compoentId = (String) attr.get(CellDataManager.SUB_COMPONENT_TEMPLATE_ID);
            Object compoentData = null;
            if (!TextUtils.isEmpty(compoentId)) {
                String virtualComponentId = context.getRenderState().getVirtualComponentIds().get(component.getViewTreeKey());
                if (virtualComponentId == null) {
                    // none virtualComponentId, create and do attach
                    virtualComponentId = CellDataManager.createVirtualComponentId(context.templateList.getRef(), component.getViewTreeKey(), context.templateList.getItemId(context.position));
                    Map<String, Object> props = renderProps((JSONObject) attr.get(ELUtils.COMPONENT_PROPS), context.stack);
                    EventResult result = WXBridgeManager.getInstance().syncCallJSEventWithResult(WXBridgeManager.METHD_COMPONENT_HOOK_SYNC, component.getInstanceId(), null, compoentId, VirtualComponentLifecycle.LIFECYCLE, VirtualComponentLifecycle.CREATE, new Object[] { virtualComponentId, props }, null);
                    if (result != null && result.getResult() != null && result.getResult() instanceof Map) {
                        props.putAll((Map<? extends String, ?>) result.getResult());
                    }
                    compoentData = props;
                    context.getRenderState().getVirtualComponentIds().put(component.getViewTreeKey(), virtualComponentId);
                    context.templateList.getCellDataManager().createVirtualComponentData(context.position, virtualComponentId, compoentData);
                    // create virtual componentId
                    WXBridgeManager.getInstance().asyncCallJSEventVoidResult(WXBridgeManager.METHD_COMPONENT_HOOK_SYNC, component.getInstanceId(), null, virtualComponentId, VirtualComponentLifecycle.LIFECYCLE, VirtualComponentLifecycle.ATTACH, null);
                } else {
                    // get virtual component data check has dirty's update
                    compoentData = context.getRenderState().getVirtualComponentDatas().get(virtualComponentId);
                    if (context.getRenderState().isHasDataUpdate()) {
                        Map<String, Object> props = renderProps((JSONObject) attr.get(ELUtils.COMPONENT_PROPS), context.stack);
                        EventResult result = WXBridgeManager.getInstance().syncCallJSEventWithResult(WXBridgeManager.METHD_COMPONENT_HOOK_SYNC, component.getInstanceId(), null, virtualComponentId, VirtualComponentLifecycle.LIFECYCLE, VirtualComponentLifecycle.SYNSTATE, new Object[] { virtualComponentId, props }, null);
                        if (result != null && result.getResult() != null && result.getResult() instanceof Map) {
                            props.putAll((Map<? extends String, ?>) result.getResult());
                            context.templateList.getCellDataManager().updateVirtualComponentData(virtualComponentId, props);
                            compoentData = props;
                        }
                    }
                }
                component.getDomObject().getAttrs().put(CellDataManager.VIRTUAL_COMPONENT_ID, virtualComponentId);
            } else {
                // stateless component
                Map<String, Object> props = renderProps((JSONObject) attr.get(ELUtils.COMPONENT_PROPS), context.stack);
                compoentData = props;
            }
            // virtual component is new context
            context.stack = new ArrayStack();
            if (compoentData != null) {
                context.stack.push(compoentData);
            }
        }
    }
    /**
     * check node is render only once, if render once, and has rendered, just return
     */
    Object vonce = null;
    if (attr.getStatement() != null) {
        vonce = attr.getStatement().get(WXStatement.WX_ONCE);
    }
    if (vonce != null) {
        ArrayStack onceStack = context.getRenderState().getOnceComponentStates().get(component.getViewTreeKey());
        if (onceStack == null) {
            onceStack = context.templateList.copyStack(context, stack);
            context.getRenderState().getOnceComponentStates().put(component.getViewTreeKey(), onceStack);
        }
        context.stack = onceStack;
    }
    doRenderBindingAttrsAndEvent(component, domObject, context);
    if (component instanceof WXVContainer) {
        if (!domObject.isShow()) {
            if (!(component instanceof WXCell)) {
                return;
            }
        }
        WXVContainer container = (WXVContainer) component;
        for (int k = 0; k < container.getChildCount(); ) {
            WXComponent next = container.getChild(k);
            k += doRenderComponent(next, context, updates);
        }
    }
    if (stack != context.stack) {
        context.stack = stack;
    }
}
Also used : WXVContainer(com.taobao.weex.ui.component.WXVContainer) EventResult(com.taobao.weex.bridge.EventResult) JSONObject(com.alibaba.fastjson.JSONObject) WXComponent(com.taobao.weex.ui.component.WXComponent) WXDomObject(com.taobao.weex.dom.WXDomObject) JSONObject(com.alibaba.fastjson.JSONObject) ArrayStack(com.taobao.weex.el.parse.ArrayStack) HashMap(java.util.HashMap) ArrayMap(android.support.v4.util.ArrayMap) Map(java.util.Map) WXCell(com.taobao.weex.ui.component.list.WXCell) WXAttr(com.taobao.weex.dom.WXAttr)

Example 3 with EventResult

use of com.taobao.weex.bridge.EventResult in project incubator-weex by apache.

the class WXComponent method fireEventWait.

public final EventResult fireEventWait(String type, Map<String, Object> params) {
    final CountDownLatch waitLatch = new CountDownLatch(1);
    EventResult callback = new EventResult() {

        @Override
        public void onCallback(Object result) {
            super.onCallback(result);
            waitLatch.countDown();
        }
    };
    try {
        fireEvent(type, params, null, callback);
        waitLatch.await(10, TimeUnit.MILLISECONDS);
        return callback;
    } catch (Exception e) {
        if (WXEnvironment.isApkDebugable()) {
            WXLogUtils.e("fireEventWait", e);
        }
        return callback;
    }
}
Also used : EventResult(com.taobao.weex.bridge.EventResult) WXDomObject(com.taobao.weex.dom.WXDomObject) JSONObject(com.alibaba.fastjson.JSONObject) IWXObject(com.taobao.weex.common.IWXObject) ImmutableDomObject(com.taobao.weex.dom.ImmutableDomObject) CountDownLatch(java.util.concurrent.CountDownLatch) WXRuntimeException(com.taobao.weex.common.WXRuntimeException)

Aggregations

JSONObject (com.alibaba.fastjson.JSONObject)3 EventResult (com.taobao.weex.bridge.EventResult)3 WXDomObject (com.taobao.weex.dom.WXDomObject)2 ArrayMap (android.support.v4.util.ArrayMap)1 IWXObject (com.taobao.weex.common.IWXObject)1 WXRuntimeException (com.taobao.weex.common.WXRuntimeException)1 ImmutableDomObject (com.taobao.weex.dom.ImmutableDomObject)1 WXAttr (com.taobao.weex.dom.WXAttr)1 ArrayStack (com.taobao.weex.el.parse.ArrayStack)1 WXComponent (com.taobao.weex.ui.component.WXComponent)1 WXVContainer (com.taobao.weex.ui.component.WXVContainer)1 WXCell (com.taobao.weex.ui.component.list.WXCell)1 HashMap (java.util.HashMap)1 Map (java.util.Map)1 CountDownLatch (java.util.concurrent.CountDownLatch)1