use of com.taobao.weex.bridge.SimpleJSCallback in project weex-example by KalicyZhou.
the class WXSDKInstance method fireModuleEvent.
/**
* Notifies WEEX that this event has occurred
* @param eventName WEEX register event
* @param module Events occur in this Module
* @param params The parameters to be notified to WEEX are required
*/
public void fireModuleEvent(String eventName, WXModule module, Map<String, Object> params) {
if (TextUtils.isEmpty(eventName) || module == null) {
return;
}
Map<String, Object> event = new HashMap<>();
event.put("type", eventName);
event.put("module", module.getModuleName());
event.put("data", params);
List<String> callbacks = module.getEventCallbacks(eventName);
if (callbacks != null) {
for (String callback : callbacks) {
SimpleJSCallback jsCallback = new SimpleJSCallback(mInstanceId, callback);
if (module.isOnce(callback)) {
jsCallback.invoke(event);
} else {
jsCallback.invokeAndKeepAlive(event);
}
}
}
}
use of com.taobao.weex.bridge.SimpleJSCallback in project incubator-weex by apache.
the class GetComponentRectAction method executeRender.
@Override
public void executeRender(RenderActionContext context) {
WXSDKInstance instance = context.getInstance();
JSCallback jsCallback = new SimpleJSCallback(context.getInstance().getInstanceId(), mCallback);
if (instance == null || instance.isDestroy()) {
// do nothing
} else if (TextUtils.isEmpty(mRef)) {
Map<String, Object> options = new HashMap<>();
options.put("result", false);
options.put("errMsg", "Illegal parameter");
jsCallback.invoke(options);
} else if ("viewport".equalsIgnoreCase(mRef)) {
callbackViewport(context, jsCallback);
} else {
WXComponent component = context.getComponent(mRef);
Map<String, Object> options = new HashMap<>();
if (component != null) {
int viewPort = instance.getInstanceViewPortWidth();
Map<String, Float> size = new HashMap<>();
Rect sizes = component.getComponentSize();
size.put("width", getWebPxValue(sizes.width(), viewPort));
size.put("height", getWebPxValue(sizes.height(), viewPort));
size.put("bottom", getWebPxValue(sizes.bottom, viewPort));
size.put("left", getWebPxValue(sizes.left, viewPort));
size.put("right", getWebPxValue(sizes.right, viewPort));
size.put("top", getWebPxValue(sizes.top, viewPort));
options.put("size", size);
options.put("result", true);
} else {
options.put("errMsg", "Component does not exist");
}
jsCallback.invoke(options);
}
}
use of com.taobao.weex.bridge.SimpleJSCallback in project incubator-weex by apache.
the class UpdateComponentDataAction method executeRender.
@Override
public void executeRender(RenderActionContext context) {
String ref = CellDataManager.getListRef(virtualComponentId);
if (TextUtils.isEmpty(ref)) {
WXLogUtils.e("wrong virtualComponentId split error " + virtualComponentId);
return;
}
WXComponent component = context.getComponent(ref);
if (component instanceof WXRecyclerTemplateList) {
WXRecyclerTemplateList templateList = (WXRecyclerTemplateList) component;
templateList.getCellDataManager().updateVirtualComponentData(virtualComponentId, data);
templateList.notifyUpdateList();
SimpleJSCallback jsCallback = new SimpleJSCallback(component.getInstanceId(), callback);
jsCallback.invoke(true);
} else {
WXLogUtils.e("recycler-list wrong virtualComponentId " + virtualComponentId);
}
}
use of com.taobao.weex.bridge.SimpleJSCallback in project incubator-weex by apache.
the class DefaultLocation method watchPosition.
@Override
public void watchPosition(final String successCallback, final String errorCallback, final String params) {
WXLogUtils.d("into--[watchPosition] successCallback:" + successCallback + " errorCallback:" + errorCallback + "\nparams:" + params);
if (!TextUtils.isEmpty(params)) {
try {
JSONObject jsObj = new JSONObject(params);
boolean enableHighAccuracy = jsObj.optBoolean("enableHighAccuracy");
boolean enableAddress = jsObj.optBoolean("address");
String id = UUID.randomUUID().toString();
WXLocationListener listener = findLocation(id, successCallback, errorCallback, enableHighAccuracy, enableAddress);
if (listener != null) {
mRegisterSucCallbacks.put(id, listener);
}
return;
} catch (JSONException e) {
WXLogUtils.e(TAG, e);
}
}
Map<String, Object> options = new HashMap<>();
options.put(ERROR_CODE, ErrorCode.PARAMS_ERROR);
options.put(ERROR_MSG, ErrorMsg.PARAMS_ERROR);
if (mWXSDKInstance != null) {
new SimpleJSCallback(mWXSDKInstance.getInstanceId(), errorCallback).invoke(options);
}
}
use of com.taobao.weex.bridge.SimpleJSCallback in project weex-example by KalicyZhou.
the class WXDomModule method getComponentRect.
/**
* By ref the width and height of the component.
*
* @param ref the refer of component
* @param callback function id
*/
public void getComponentRect(String ref, String callback) {
if (mWXSDKInstance == null) {
return;
}
SimpleJSCallback jsCallback = new SimpleJSCallback(mWXSDKInstance.getInstanceId(), callback);
if (TextUtils.isEmpty(ref)) {
Map<String, Object> options = new HashMap<>();
options.put("result", false);
options.put("errMsg", "Illegal parameter");
jsCallback.invoke(options);
return;
} else if ("viewport".equalsIgnoreCase(ref)) {
if (mWXSDKInstance.getContainerView() != null) {
Map<String, Object> options = new HashMap<>();
Map<String, String> sizes = new HashMap<>();
int[] location = new int[2];
mWXSDKInstance.getContainerView().getLocationOnScreen(location);
sizes.put("left", "0");
sizes.put("top", "0");
sizes.put("right", getWebPxValue(mWXSDKInstance.getContainerView().getWidth()));
sizes.put("bottom", getWebPxValue(mWXSDKInstance.getContainerView().getHeight()));
sizes.put("width", getWebPxValue(mWXSDKInstance.getContainerView().getWidth()));
sizes.put("height", getWebPxValue(mWXSDKInstance.getContainerView().getHeight()));
options.put("size", sizes);
options.put("result", true);
jsCallback.invoke(options);
} else {
Map<String, Object> options = new HashMap<>();
options.put("result", false);
options.put("errMsg", "Component does not exist");
jsCallback.invoke(options);
}
} else {
Message msg = Message.obtain();
WXDomTask task = new WXDomTask();
task.instanceId = mWXSDKInstance.getInstanceId();
task.args = new ArrayList<>();
task.args.add(ref);
task.args.add(jsCallback);
msg.what = WXDomHandler.MsgType.WX_COMPONENT_SIZE;
msg.obj = task;
WXSDKManager.getInstance().getWXDomManager().sendMessage(msg);
}
}
Aggregations