Search in sources :

Example 1 with FlatComponent

use of com.taobao.weex.ui.flat.FlatComponent in project incubator-weex by apache.

the class WXComponent method setPadding.

public void setPadding(Spacing padding, Spacing border) {
    int left = (int) (padding.get(Spacing.LEFT) + border.get(Spacing.LEFT));
    int top = (int) (padding.get(Spacing.TOP) + border.get(Spacing.TOP));
    int right = (int) (padding.get(Spacing.RIGHT) + border.get(Spacing.RIGHT));
    int bottom = (int) (padding.get(Spacing.BOTTOM) + border.get(Spacing.BOTTOM));
    if (this instanceof FlatComponent && !((FlatComponent) this).promoteToView(true)) {
        ((FlatComponent) this).getOrCreateFlatWidget().setContentBox(left, top, right, bottom);
    } else if (mHost != null) {
        mHost.setPadding(left, top, right, bottom);
    }
}
Also used : FlatComponent(com.taobao.weex.ui.flat.FlatComponent) Point(android.graphics.Point)

Example 2 with FlatComponent

use of com.taobao.weex.ui.flat.FlatComponent in project incubator-weex by apache.

the class WXComponent method setComponentLayoutParams.

private void setComponentLayoutParams(int realWidth, int realHeight, int realLeft, int realTop, int realRight, int realBottom, Point rawOffset) {
    if (getInstance() == null || getInstance().isDestroy()) {
        return;
    }
    FlatGUIContext UIImp = getInstance().getFlatUIContext();
    WidgetContainer ancestor;
    Widget widget;
    if (UIImp != null && (ancestor = UIImp.getFlatComponentAncestor(this)) != null) {
        if (this instanceof FlatComponent && !((FlatComponent) this).promoteToView(true)) {
            widget = ((FlatComponent) this).getOrCreateFlatWidget();
        } else {
            widget = UIImp.getAndroidViewWidget(this);
        }
        setWidgetParams(widget, UIImp, rawOffset, realWidth, realHeight, realLeft, realRight, realTop, realBottom);
    } else if (mHost != null) {
        // clear box shadow before host's size changed
        clearBoxShadow();
        if (mDomObj.isFixed()) {
            setFixedHostLayoutParams(mHost, realWidth, realHeight, realLeft, realRight, realTop, realBottom);
        } else {
            setHostLayoutParams(mHost, realWidth, realHeight, realLeft, realRight, realTop, realBottom);
        }
        mPreRealWidth = realWidth;
        mPreRealHeight = realHeight;
        mPreRealLeft = realLeft;
        mPreRealTop = realTop;
        onFinishLayout();
        // restore box shadow
        updateBoxShadow();
    }
}
Also used : FlatComponent(com.taobao.weex.ui.flat.FlatComponent) FlatGUIContext(com.taobao.weex.ui.flat.FlatGUIContext) Widget(com.taobao.weex.ui.flat.widget.Widget) AndroidViewWidget(com.taobao.weex.ui.flat.widget.AndroidViewWidget) WidgetContainer(com.taobao.weex.ui.flat.WidgetContainer)

Example 3 with FlatComponent

use of com.taobao.weex.ui.flat.FlatComponent in project incubator-weex by apache.

the class WXComponent method updateProperties.

@Deprecated
public void updateProperties(Map<String, Object> props) {
    if (props == null || (mHost == null && !isVirtualComponent())) {
        return;
    }
    for (Map.Entry<String, Object> entry : props.entrySet()) {
        String key = entry.getKey();
        Object param = entry.getValue();
        String value = WXUtils.getString(param, null);
        if (TextUtils.isEmpty(value)) {
            param = convertEmptyProperty(key, value);
        }
        if (!setProperty(key, param)) {
            if (mHolder == null) {
                return;
            }
            Invoker invoker = mHolder.getPropertyInvoker(key);
            if (invoker != null) {
                try {
                    Type[] paramClazzs = invoker.getParameterTypes();
                    if (paramClazzs.length != 1) {
                        WXLogUtils.e("[WXComponent] setX method only one parameter:" + invoker);
                        return;
                    }
                    param = WXReflectionUtils.parseArgument(paramClazzs[0], param);
                    invoker.invoke(this, param);
                } catch (Exception e) {
                    WXLogUtils.e("[WXComponent] updateProperties :" + "class:" + getClass() + "method:" + invoker.toString() + " function " + WXLogUtils.getStackTrace(e));
                }
            }
        }
    }
    readyToRender();
    if (this instanceof FlatComponent && mBackgroundDrawable != null) {
        FlatComponent flatComponent = (FlatComponent) this;
        if (!flatComponent.promoteToView(true) && !(flatComponent.getOrCreateFlatWidget() instanceof AndroidViewWidget)) {
            flatComponent.getOrCreateFlatWidget().setBackgroundAndBorder(mBackgroundDrawable);
        }
    }
}
Also used : FlatComponent(com.taobao.weex.ui.flat.FlatComponent) Type(java.lang.reflect.Type) ElementType(java.lang.annotation.ElementType) WXGestureType(com.taobao.weex.ui.view.gesture.WXGestureType) Invoker(com.taobao.weex.bridge.Invoker) AndroidViewWidget(com.taobao.weex.ui.flat.widget.AndroidViewWidget) WXDomObject(com.taobao.weex.dom.WXDomObject) JSONObject(com.alibaba.fastjson.JSONObject) IWXObject(com.taobao.weex.common.IWXObject) ImmutableDomObject(com.taobao.weex.dom.ImmutableDomObject) Map(java.util.Map) HashMap(java.util.HashMap) WXRuntimeException(com.taobao.weex.common.WXRuntimeException)

Example 4 with FlatComponent

use of com.taobao.weex.ui.flat.FlatComponent in project incubator-weex by apache.

the class WXComponent method setWidgetParams.

private void setWidgetParams(Widget widget, FlatGUIContext UIImp, Point rawoffset, int width, int height, int left, int right, int top, int bottom) {
    Point childOffset = new Point();
    if (mParent != null) {
        if (mParent instanceof FlatComponent && UIImp.getFlatComponentAncestor(mParent) != null && UIImp.getAndroidViewWidget(mParent) == null) {
            childOffset.set(rawoffset.x, rawoffset.y);
        } else {
            childOffset.set(left, top);
        }
        if (mParent instanceof FlatComponent && UIImp.getFlatComponentAncestor(mParent) != null && UIImp.getAndroidViewWidget(mParent) == null) {
            Point parentLayoutOffset = ((FlatComponent) mParent).getOrCreateFlatWidget().getLocInFlatContainer();
            childOffset.offset(parentLayoutOffset.x, parentLayoutOffset.y);
        }
        ViewGroup.LayoutParams lp = mParent.getChildLayoutParams(this, mHost, width, height, left, right, top, bottom);
        if (lp instanceof MarginLayoutParams) {
            width = lp.width;
            height = lp.height;
            left = ((MarginLayoutParams) lp).leftMargin;
            right = ((MarginLayoutParams) lp).rightMargin;
            top = ((MarginLayoutParams) lp).topMargin;
            bottom = ((MarginLayoutParams) lp).bottomMargin;
        }
    }
    widget.setLayout(width, height, left, right, top, bottom, childOffset);
    if (widget instanceof AndroidViewWidget && ((AndroidViewWidget) widget).getView() != null) {
        // TODO generic method if ever possible
        setHostLayoutParams((T) ((AndroidViewWidget) widget).getView(), width, height, childOffset.x, right, childOffset.y, bottom);
    }
}
Also used : FlatComponent(com.taobao.weex.ui.flat.FlatComponent) ViewGroup(android.view.ViewGroup) AndroidViewWidget(com.taobao.weex.ui.flat.widget.AndroidViewWidget) Point(android.graphics.Point) MarginLayoutParams(android.view.ViewGroup.MarginLayoutParams)

Aggregations

FlatComponent (com.taobao.weex.ui.flat.FlatComponent)4 AndroidViewWidget (com.taobao.weex.ui.flat.widget.AndroidViewWidget)3 Point (android.graphics.Point)2 ViewGroup (android.view.ViewGroup)1 MarginLayoutParams (android.view.ViewGroup.MarginLayoutParams)1 JSONObject (com.alibaba.fastjson.JSONObject)1 Invoker (com.taobao.weex.bridge.Invoker)1 IWXObject (com.taobao.weex.common.IWXObject)1 WXRuntimeException (com.taobao.weex.common.WXRuntimeException)1 ImmutableDomObject (com.taobao.weex.dom.ImmutableDomObject)1 WXDomObject (com.taobao.weex.dom.WXDomObject)1 FlatGUIContext (com.taobao.weex.ui.flat.FlatGUIContext)1 WidgetContainer (com.taobao.weex.ui.flat.WidgetContainer)1 Widget (com.taobao.weex.ui.flat.widget.Widget)1 WXGestureType (com.taobao.weex.ui.view.gesture.WXGestureType)1 ElementType (java.lang.annotation.ElementType)1 Type (java.lang.reflect.Type)1 HashMap (java.util.HashMap)1 Map (java.util.Map)1