Search in sources :

Example 1 with FlatGUIContext

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

the class WXTextTest method setUp.

@Before
public void setUp() throws Exception {
    WXEnvironment.sApplication = RuntimeEnvironment.application;
    WXSDKInstance instance = Mockito.mock(WXSDKInstance.class);
    Mockito.when(instance.getContext()).thenReturn(RuntimeEnvironment.application);
    Mockito.when(instance.getFlatUIContext()).thenReturn(new FlatGUIContext());
    mParentDomObj = Mockito.spy(new WXDomObject());
    Mockito.when(mParentDomObj.getPadding()).thenReturn(new Spacing());
    Mockito.when(mParentDomObj.getBorder()).thenReturn(new Spacing());
    Mockito.when(mParentDomObj.clone()).thenReturn(mParentDomObj);
    TestDomObject.setRef(mParentDomObj, WXDomObject.ROOT);
    mDomObject = Mockito.spy(new WXTextDomObject());
    TestDomObject.setRef(mDomObject, "1");
    mDomObject.addEvent(Constants.Event.CLICK);
    Mockito.when(mDomObject.clone()).thenReturn(mDomObject);
    Mockito.when(mDomObject.getPadding()).thenReturn(new Spacing());
    Mockito.when(mDomObject.getBorder()).thenReturn(new Spacing());
    Mockito.when(mDomObject.getMargin()).thenReturn(new Spacing());
    Mockito.when(mDomObject.getLayoutWidth()).thenReturn(100f);
    Mockito.when(mDomObject.getLayoutHeight()).thenReturn(100f);
    mParent = new WXDiv(instance, mParentDomObj, null);
    mParent.createView();
    mWXText = new WXText(instance, mDomObject, mParent);
    mWXText.bindHolder(new SimpleComponentHolder(WXText.class));
    assertNotNull(instance.getContext());
}
Also used : WXSDKInstance(com.taobao.weex.WXSDKInstance) FlatGUIContext(com.taobao.weex.ui.flat.FlatGUIContext) WXDomObject(com.taobao.weex.dom.WXDomObject) WXTextDomObject(com.taobao.weex.dom.WXTextDomObject) SimpleComponentHolder(com.taobao.weex.ui.SimpleComponentHolder) Spacing(com.taobao.weex.dom.flex.Spacing) Before(org.junit.Before)

Example 2 with FlatGUIContext

use of com.taobao.weex.ui.flat.FlatGUIContext 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 3 with FlatGUIContext

use of com.taobao.weex.ui.flat.FlatGUIContext 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 4 with FlatGUIContext

use of com.taobao.weex.ui.flat.FlatGUIContext 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)

Aggregations

FlatGUIContext (com.taobao.weex.ui.flat.FlatGUIContext)4 WXSDKInstance (com.taobao.weex.WXSDKInstance)3 WXDomObject (com.taobao.weex.dom.WXDomObject)3 Spacing (com.taobao.weex.dom.flex.Spacing)3 Before (org.junit.Before)2 WXSDKInstanceTest (com.taobao.weex.WXSDKInstanceTest)1 WXEvent (com.taobao.weex.dom.WXEvent)1 WXTextDomObject (com.taobao.weex.dom.WXTextDomObject)1 SimpleComponentHolder (com.taobao.weex.ui.SimpleComponentHolder)1 FlatComponent (com.taobao.weex.ui.flat.FlatComponent)1 WidgetContainer (com.taobao.weex.ui.flat.WidgetContainer)1 AndroidViewWidget (com.taobao.weex.ui.flat.widget.AndroidViewWidget)1 Widget (com.taobao.weex.ui.flat.widget.Widget)1 Test (org.junit.Test)1