use of com.taobao.weex.WXSDKInstance in project weex-example by KalicyZhou.
the class WXDivTest method testAddChild.
@Test
public void testAddChild() {
WXSDKInstance instance = Mockito.mock(WXSDKInstance.class);
Mockito.when(instance.getContext()).thenReturn(RuntimeEnvironment.application);
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.WXSDKInstance in project weex-example by KalicyZhou.
the class WXBridge method callNative.
public int callNative(String instanceId, String tasks, String callback) {
long start = System.currentTimeMillis();
WXSDKInstance instance = WXSDKManager.getInstance().getSDKInstance(instanceId);
if (instance != null) {
instance.firstScreenCreateInstanceTime(start);
}
int errorCode = IWXBridge.INSTANCE_RENDERING;
try {
errorCode = WXBridgeManager.getInstance().callNative(instanceId, tasks, callback);
} catch (Throwable e) {
//catch everything during call native.
if (WXEnvironment.isApkDebugable()) {
WXLogUtils.e(TAG, "callNative throw exception:" + e.getMessage());
}
}
if (instance != null) {
instance.callNativeTime(System.currentTimeMillis() - start);
}
if (WXEnvironment.isApkDebugable()) {
if (errorCode == IWXBridge.DESTROY_INSTANCE) {
WXLogUtils.w("destroyInstance :" + instanceId + " JSF must stop callNative");
}
}
return errorCode;
}
use of com.taobao.weex.WXSDKInstance in project weex-example by KalicyZhou.
the class WXDomStatement method updateFinish.
/**
* Create a command object for notifying {@link WXRenderManager} that the process of update
* given view is finished, and put the command object in the queue.
*/
void updateFinish() {
if (mDestroy) {
return;
}
mNormalTasks.add(new IWXRenderTask() {
@Override
public void execute() {
mWXRenderManager.updateFinish(mInstanceId);
}
@Override
public String toString() {
return "updateFinish";
}
});
WXSDKInstance instance = WXSDKManager.getInstance().getSDKInstance(mInstanceId);
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 scrollToDom.
/**
* Create a command object for scroll the given view to the specified position.
* @param ref Reference of the dom.
* @param options the specified position
*/
void scrollToDom(final String ref, final JSONObject options) {
if (mDestroy) {
return;
}
WXSDKInstance instance = WXSDKManager.getInstance().getSDKInstance(mInstanceId);
mNormalTasks.add(new IWXRenderTask() {
@Override
public void execute() {
mWXRenderManager.scrollToComponent(mInstanceId, ref, options);
}
@Override
public String toString() {
return "scrollToPosition";
}
});
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 removeEvent.
/**
* Create a command object for removing the event listener of the corresponding {@link
* WXDomObject} and put the command event in the queue.
* @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 removeEvent(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_REMOVEEVENT);
}
return;
}
domObject.removeEvent(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.removeEvent(mInstanceId, ref, type);
}
}
@Override
public String toString() {
return "removeEvent";
}
});
mDirty = true;
if (instance != null) {
instance.commitUTStab(IWXUserTrackAdapter.DOM_MODULE, WXErrorCode.WX_SUCCESS);
}
}
Aggregations