Search in sources :

Example 11 with Spacing

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

the class StatementTest method setUp.

@Before
public void setUp() throws Exception {
    WXSDKInstance instance = Mockito.mock(WXSDKInstance.class);
    Mockito.when(instance.getContext()).thenReturn(RuntimeEnvironment.application);
    WXDomObject divDom = new WXDomObject();
    WXDomObject spy = Mockito.spy(divDom);
    Mockito.when(spy.getPadding()).thenReturn(new Spacing());
    Mockito.when(spy.getEvents()).thenReturn(new WXEvent());
    Mockito.when(spy.clone()).thenReturn(divDom);
    TestDomObject.setRef(divDom, "1");
}
Also used : WXSDKInstance(com.taobao.weex.WXSDKInstance) WXDomObject(com.taobao.weex.dom.WXDomObject) WXEvent(com.taobao.weex.dom.WXEvent) Spacing(com.taobao.weex.dom.flex.Spacing) Before(org.junit.Before)

Example 12 with Spacing

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

the class WXDivTest method testAddChild.

@Test
public void testAddChild() {
    WXSDKInstance instance = Mockito.mock(WXSDKInstance.class);
    Mockito.when(instance.getContext()).thenReturn(RuntimeEnvironment.application);
    Mockito.when(instance.getFlatUIContext()).thenReturn(new FlatGUIContext());
    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) FlatGUIContext(com.taobao.weex.ui.flat.FlatGUIContext) WXDomObject(com.taobao.weex.dom.WXDomObject) Spacing(com.taobao.weex.dom.flex.Spacing) Test(org.junit.Test) WXSDKInstanceTest(com.taobao.weex.WXSDKInstanceTest)

Example 13 with Spacing

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

the class WXDivTest method setUp.

@Before
public void setUp() throws Exception {
    WXSDKInstance instance = Mockito.mock(WXSDKInstance.class);
    Mockito.when(instance.getContext()).thenReturn(RuntimeEnvironment.application);
    Mockito.when(instance.getFlatUIContext()).thenReturn(new FlatGUIContext());
    WXDomObject divDom = new WXDomObject();
    WXDomObject spy = Mockito.spy(divDom);
    Mockito.when(spy.getPadding()).thenReturn(new Spacing());
    Mockito.when(spy.getEvents()).thenReturn(new WXEvent());
    Mockito.when(spy.clone()).thenReturn(divDom);
    TestDomObject.setRef(divDom, "1");
    mWXDiv = new WXDiv(instance, divDom, null);
    mWXDiv.initView();
}
Also used : WXSDKInstance(com.taobao.weex.WXSDKInstance) FlatGUIContext(com.taobao.weex.ui.flat.FlatGUIContext) WXDomObject(com.taobao.weex.dom.WXDomObject) WXEvent(com.taobao.weex.dom.WXEvent) Spacing(com.taobao.weex.dom.flex.Spacing) Before(org.junit.Before)

Example 14 with Spacing

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

the class WXComponent method setLayout.

/**
 * layout view
 */
public final void setLayout(ImmutableDomObject domObject) {
    if (domObject == null || TextUtils.isEmpty(mCurrentRef)) {
        return;
    }
    // parent is nullable
    boolean nullParent = mParent == null;
    mDomObj = domObject;
    // offset by sibling
    int siblingOffset = nullParent ? 0 : mParent.getChildrenLayoutTopOffset();
    Spacing parentPadding = (nullParent ? new Spacing() : mParent.getDomObject().getPadding());
    Spacing parentBorder = (nullParent ? new Spacing() : mParent.getDomObject().getBorder());
    Spacing margin = mDomObj.getMargin();
    int realWidth = (int) mDomObj.getLayoutWidth();
    int realHeight = (int) mDomObj.getLayoutHeight();
    int realLeft = (int) (mDomObj.getLayoutX() - parentPadding.get(Spacing.LEFT) - parentBorder.get(Spacing.LEFT));
    int realTop = (int) (mDomObj.getLayoutY() - parentPadding.get(Spacing.TOP) - parentBorder.get(Spacing.TOP)) + siblingOffset;
    int realRight = (int) margin.get(Spacing.RIGHT);
    int realBottom = (int) margin.get(Spacing.BOTTOM);
    Point rawOffset = new Point((int) mDomObj.getCSSLayoutLeft(), (int) mDomObj.getCSSLayoutTop());
    if (mPreRealWidth == realWidth && mPreRealHeight == realHeight && mPreRealLeft == realLeft && mPreRealTop == realTop) {
        return;
    }
    if (realHeight >= WXPerformance.VIEW_LIMIT_HEIGHT && realWidth >= WXPerformance.VIEW_LIMIT_WIDTH) {
        mInstance.getWXPerformance().cellExceedNum++;
    }
    mAbsoluteY = (int) (nullParent ? 0 : mParent.getAbsoluteY() + mDomObj.getLayoutY());
    mAbsoluteX = (int) (nullParent ? 0 : mParent.getAbsoluteX() + mDomObj.getLayoutX());
    // calculate first screen time
    if (!mInstance.mEnd && !(mHost instanceof ViewGroup) && mAbsoluteY + realHeight > mInstance.getWeexHeight() + 1) {
        mInstance.firstScreenRenderFinished();
    }
    MeasureOutput measureOutput = measure(realWidth, realHeight);
    realWidth = measureOutput.width;
    realHeight = measureOutput.height;
    setComponentLayoutParams(realWidth, realHeight, realLeft, realTop, realRight, realBottom, rawOffset);
}
Also used : ViewGroup(android.view.ViewGroup) Spacing(com.taobao.weex.dom.flex.Spacing) Point(android.graphics.Point) Point(android.graphics.Point)

Example 15 with Spacing

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

the class WXDomUtils method getContentWidth.

/**
 * Get the content width of the dom.
 * @return the width of the dom that excludes left-padding, left-border-width,
 * right-border-width and right-padding.
 */
public static float getContentWidth(ImmutableDomObject domObject) {
    float rawWidth = domObject.getLayoutWidth();
    float leftPadding, rightPadding, leftBorder, rightBorder;
    Spacing padding = domObject.getPadding();
    Spacing border = domObject.getBorder();
    if (!CSSConstants.isUndefined((leftPadding = padding.get(Spacing.LEFT)))) {
        rawWidth -= leftPadding;
    }
    if (!CSSConstants.isUndefined((rightPadding = padding.get(Spacing.RIGHT)))) {
        rawWidth -= rightPadding;
    }
    if (!CSSConstants.isUndefined(leftBorder = border.get(Spacing.LEFT))) {
        rawWidth -= leftBorder;
    }
    if (!CSSConstants.isUndefined(rightBorder = border.get(Spacing.RIGHT))) {
        rawWidth -= rightBorder;
    }
    return rawWidth;
}
Also used : Spacing(com.taobao.weex.dom.flex.Spacing)

Aggregations

Spacing (com.taobao.weex.dom.flex.Spacing)15 WXSDKInstance (com.taobao.weex.WXSDKInstance)7 WXDomObject (com.taobao.weex.dom.WXDomObject)7 Before (org.junit.Before)5 WXEvent (com.taobao.weex.dom.WXEvent)3 FlatGUIContext (com.taobao.weex.ui.flat.FlatGUIContext)3 ViewGroup (android.view.ViewGroup)2 WXSDKInstanceTest (com.taobao.weex.WXSDKInstanceTest)2 WXTextDomObject (com.taobao.weex.dom.WXTextDomObject)2 SimpleComponentHolder (com.taobao.weex.ui.SimpleComponentHolder)2 Test (org.junit.Test)2 Point (android.graphics.Point)1 WXStyle (com.taobao.weex.dom.WXStyle)1 WXComponent (com.taobao.weex.ui.component.WXComponent)1