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());
}
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));
}
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();
}
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();
}
}
Aggregations