use of com.taobao.weex.WXSDKInstance in project weex-example by KalicyZhou.
the class WXRenderStatementTest method setUp.
@Before
public void setUp() throws Exception {
PowerMockito.mockStatic(WXSoInstallMgrSdk.class);
PowerMockito.mockStatic(TextUtils.class);
PowerMockito.mockStatic(WXComponentFactory.class);
PowerMockito.when(TextUtils.isEmpty("124")).thenReturn(true);
PowerMockito.when(WXSoInstallMgrSdk.initSo(null, 1, null)).thenReturn(true);
WXSDKInstance instance = Mockito.mock(WXSDKInstance.class);
mWXRenderStatement = new WXRenderStatement(instance);
}
use of com.taobao.weex.WXSDKInstance in project weex-example by KalicyZhou.
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);
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.WXSDKInstance in project weex-example by KalicyZhou.
the class WXDivTest 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");
mWXDiv = new WXDiv(instance, divDom, null);
mWXDiv.initView();
}
use of com.taobao.weex.WXSDKInstance in project weex-example by KalicyZhou.
the class WXDomStatement method addEvent.
/**
* Create a command object for adding a default event listener to the corresponding {@link
* WXDomObject} and put the command object in the queue.
* When the event is triggered, the eventListener will call {@link WXSDKManager#fireEvent(String, String, String)}
* , and the JS will handle all the operations from there.
*
* @param ref Reference of the dom.
* @param type the type of the event, this may be a plain event defined in
* {@link com.taobao.weex.common.Constants.Event} or a gesture defined in {@link com.taobao
* .weex.ui.view.gesture.WXGestureType}
*/
void addEvent(final String ref, final String type) {
if (mDestroy) {
return;
}
WXSDKInstance instance = WXSDKManager.getInstance().getSDKInstance(mInstanceId);
final WXDomObject domObject = mRegistry.get(ref);
if (domObject == null) {
if (instance != null) {
instance.commitUTStab(IWXUserTrackAdapter.DOM_MODULE, WXErrorCode.WX_ERR_DOM_ADDEVENT);
}
return;
}
domObject.addEvent(type);
mNormalTasks.add(new IWXRenderTask() {
@Override
public void execute() {
WXComponent comp = mWXRenderManager.getWXComponent(mInstanceId, ref);
if (comp != null) {
//sync dom change to component
comp.updateDom(domObject);
mWXRenderManager.addEvent(mInstanceId, ref, type);
}
}
@Override
public String toString() {
return "Add event";
}
});
mDirty = true;
if (instance != null) {
instance.commitUTStab(IWXUserTrackAdapter.DOM_MODULE, WXErrorCode.WX_SUCCESS);
}
}
use of com.taobao.weex.WXSDKInstance in project weex-example by KalicyZhou.
the class WXDomStatement method addDomInternal.
/**
* Add DOM node.
* @param dom
* @param isRoot
* @param parentRef
* @param index
*/
private void addDomInternal(JSONObject dom, boolean isRoot, String parentRef, final int index) {
if (mDestroy) {
return;
}
WXSDKInstance instance = WXSDKManager.getInstance().getSDKInstance(mInstanceId);
if (instance == null) {
return;
}
WXErrorCode errCode = isRoot ? WXErrorCode.WX_ERR_DOM_CREATEBODY : WXErrorCode.WX_ERR_DOM_ADDELEMENT;
if (dom == null) {
instance.commitUTStab(IWXUserTrackAdapter.DOM_MODULE, errCode);
}
//only non-root has parent.
WXDomObject parent;
WXDomObject domObject = WXDomObject.parse(dom, instance);
if (domObject == null || mRegistry.containsKey(domObject.getRef())) {
if (WXEnvironment.isApkDebugable()) {
WXLogUtils.e("[WXDomStatement] " + (isRoot ? "createBody" : "addDom") + " error,DOM object is null or already registered!!");
}
instance.commitUTStab(IWXUserTrackAdapter.DOM_MODULE, errCode);
return;
}
if (isRoot) {
WXDomObject.prepareRoot(domObject, WXViewUtils.getWebPxByWidth(WXViewUtils.getWeexHeight(mInstanceId), WXSDKManager.getInstanceViewPortWidth(mInstanceId)), WXViewUtils.getWebPxByWidth(WXViewUtils.getWeexWidth(mInstanceId), WXSDKManager.getInstanceViewPortWidth(mInstanceId)));
} else if ((parent = mRegistry.get(parentRef)) == null) {
instance.commitUTStab(IWXUserTrackAdapter.DOM_MODULE, errCode);
return;
} else {
//non-root and parent exist
parent.add(domObject, index);
}
domObject.traverseTree(mAddDOMConsumer, ApplyStyleConsumer.getInstance());
//Create component in dom thread
WXComponent component = isRoot ? mWXRenderManager.createBodyOnDomThread(mInstanceId, domObject) : mWXRenderManager.createComponentOnDomThread(mInstanceId, domObject, parentRef, index);
if (component == null) {
instance.commitUTStab(IWXUserTrackAdapter.DOM_MODULE, errCode);
//stop redner, some fatal happened.
return;
}
AddDomInfo addDomInfo = new AddDomInfo();
addDomInfo.component = component;
mAddDom.put(domObject.getRef(), addDomInfo);
IWXRenderTask task = isRoot ? new CreateBodyTask(component) : new AddDOMTask(component, parentRef, index);
mNormalTasks.add(task);
addAnimationForDomTree(domObject);
mDirty = true;
instance.commitUTStab(IWXUserTrackAdapter.DOM_MODULE, WXErrorCode.WX_SUCCESS);
}
Aggregations