Search in sources :

Example 11 with WXStyle

use of com.taobao.weex.dom.WXStyle in project WeexErosFramework by bmfe.

the class BMPop method getAnimationHeight.

private void getAnimationHeight() {
    WXDomObject wxDomObject = (WXDomObject) getDomObject();
    if (wxDomObject == null)
        return;
    WXStyle wxStyle = wxDomObject.getStyles();
    Object object = wxStyle.get("height");
    if (object == null)
        return;
    mHeight = Integer.valueOf(object.toString());
}
Also used : WXStyle(com.taobao.weex.dom.WXStyle) WXDomObject(com.taobao.weex.dom.WXDomObject) WXDomObject(com.taobao.weex.dom.WXDomObject)

Example 12 with WXStyle

use of com.taobao.weex.dom.WXStyle in project incubator-weex by apache.

the class Statements method doRenderBindingAttrsAndEvent.

/**
 * render dynamic binding attrs and bind them to component node.
 */
private static void doRenderBindingAttrsAndEvent(WXComponent component, WXDomObject domObject, CellRenderContext context) {
    ArrayStack stack = context.stack;
    component.setWaste(false);
    WXAttr attr = domObject.getAttrs();
    if (attr != null && attr.getBindingAttrs() != null && attr.getBindingAttrs().size() > 0) {
        ArrayMap<String, Object> bindAttrs = domObject.getAttrs().getBindingAttrs();
        Map<String, Object> dynamic = renderBindingAttrs(bindAttrs, stack);
        Set<Map.Entry<String, Object>> entries = dynamic.entrySet();
        /**
         * diff attrs, see attrs has update, remove none update attrs
         */
        Iterator<Map.Entry<String, Object>> iterator = entries.iterator();
        while (iterator.hasNext()) {
            Map.Entry<String, Object> entry = iterator.next();
            String key = entry.getKey();
            Object value = entry.getValue();
            Object oldValue = attr.get(key);
            if (value == null) {
                if (oldValue == null) {
                    iterator.remove();
                    continue;
                }
            } else {
                if (value.equals(oldValue)) {
                    iterator.remove();
                }
            }
        }
        if (dynamic.size() > 0) {
            if (dynamic.size() == 1 && dynamic.get(Constants.Name.SRC) != null && component instanceof WXImage) {
                // for image avoid dirty layout, only update src attrs
                domObject.getAttrs().put(Constants.Name.SRC, dynamic.get(Constants.Name.SRC));
            } else {
                // dirty layout
                domObject.updateAttr(dynamic);
            }
            if (isMainThread()) {
                component.updateProperties(dynamic);
            }
            dynamic.clear();
        }
    }
    WXStyle style = domObject.getStyles();
    if (style != null && style.getBindingStyle() != null) {
        ArrayMap<String, Object> bindStyle = style.getBindingStyle();
        Map<String, Object> dynamic = renderBindingAttrs(bindStyle, stack);
        Set<Map.Entry<String, Object>> entries = dynamic.entrySet();
        /**
         * diff attrs, see attrs has update, remove none update attrs
         */
        Iterator<Map.Entry<String, Object>> iterator = entries.iterator();
        while (iterator.hasNext()) {
            Map.Entry<String, Object> entry = iterator.next();
            String key = entry.getKey();
            Object value = entry.getValue();
            Object oldValue = style.get(key);
            if (value == null) {
                if (oldValue == null) {
                    iterator.remove();
                    continue;
                }
            } else {
                if (value.equals(oldValue)) {
                    iterator.remove();
                }
            }
        }
        if (dynamic.size() > 0) {
            domObject.updateStyle(dynamic, false);
            domObject.applyStyle(dynamic);
            if (isMainThread()) {
                component.updateProperties(dynamic);
            }
        }
    }
    WXEvent event = domObject.getEvents();
    if (event == null || event.getEventBindingArgs() == null) {
        return;
    }
    Set<Map.Entry<String, Object>> eventBindArgsEntrySet = event.getEventBindingArgs().entrySet();
    for (Map.Entry<String, Object> eventBindArgsEntry : eventBindArgsEntrySet) {
        List<Object> values = getBindingEventArgs(stack, eventBindArgsEntry.getValue());
        if (values != null) {
            event.putEventBindingArgsValue(eventBindArgsEntry.getKey(), values);
        }
    }
}
Also used : WXStyle(com.taobao.weex.dom.WXStyle) ArrayStack(com.taobao.weex.el.parse.ArrayStack) WXEvent(com.taobao.weex.dom.WXEvent) WXDomObject(com.taobao.weex.dom.WXDomObject) JSONObject(com.alibaba.fastjson.JSONObject) WXImage(com.taobao.weex.ui.component.WXImage) HashMap(java.util.HashMap) ArrayMap(android.support.v4.util.ArrayMap) Map(java.util.Map) WXAttr(com.taobao.weex.dom.WXAttr)

Example 13 with WXStyle

use of com.taobao.weex.dom.WXStyle in project incubator-weex by apache.

the class FlatGUIContext method checkComponent.

private boolean checkComponent(@NonNull WXComponent component) {
    boolean ret = false;
    ImmutableDomObject domObject = component.getDomObject();
    if (domObject != null) {
        WXStyle style = domObject.getStyles();
        WXAttr attr = domObject.getAttrs();
        if (style.containsKey(Name.OPACITY) || style.containsKey(Name.TRANSFORM) || style.containsKey(Name.VISIBILITY) || attr.containsKey(Name.ELEVATION) || attr.containsKey(Name.ARIA_HIDDEN) || attr.containsKey(Name.ARIA_LABEL) || attr.containsKey(WXComponent.PROP_FIXED_SIZE) || attr.containsKey(Name.DISABLED) || style.isFixed() || style.isSticky() || !style.getPesudoStyles().isEmpty() || domObject.getEvents().size() > 0) {
            ret = true;
        }
    }
    return ret;
}
Also used : WXStyle(com.taobao.weex.dom.WXStyle) ImmutableDomObject(com.taobao.weex.dom.ImmutableDomObject) WXAttr(com.taobao.weex.dom.WXAttr)

Aggregations

WXStyle (com.taobao.weex.dom.WXStyle)13 WXDomObject (com.taobao.weex.dom.WXDomObject)9 JSONObject (com.alibaba.fastjson.JSONObject)6 WXAttr (com.taobao.weex.dom.WXAttr)5 ImmutableDomObject (com.taobao.weex.dom.ImmutableDomObject)4 IWXObject (com.taobao.weex.common.IWXObject)3 HashMap (java.util.HashMap)3 Map (java.util.Map)3 Point (android.graphics.Point)1 ArrayMap (android.support.v4.util.ArrayMap)1 View (android.view.View)1 WXEvent (com.taobao.weex.dom.WXEvent)1 Spacing (com.taobao.weex.dom.flex.Spacing)1 ArrayStack (com.taobao.weex.el.parse.ArrayStack)1 WXImage (com.taobao.weex.ui.component.WXImage)1