WXSDKInstace

Weex Native 和 JavaScript 交互通信.

自定义发送事件

向JS环境发送一些事件,比如click事件 1. void fireEvent(elementRef,type) 2. void fireEvent(elementRef,type, data) 3. void fireEvent(elementRef,type,data,domChanges)

  • elementRef(String):产生事件的组件id
  • type(String): 事件名称,weex默认事件名称格式为"onXXX",比如OnPullDown
  • data(Map): 需要发送的一些额外数据,比如click时,view大小,点击坐标等等。
  • domChanges(Map): 目标组件的属性和样式发生的修改内容

结果回调

JS调用时,有的场景需要返回一些数,比如以下例子,返回x、y坐标 1. public class WXLocation extends WXModule { 2. 3. @JSMethod 4. public void getLocation(JSCallback callback){ 5. //Get the code for the location information ..... 6. Map data=new HashMap<>(); 7. data.put("x","x"); 8. data.put("y","y"); 9. //notify once 10. callback.invoke(data); 11. //Continuous connection 12. callback.invokeAndKeepAlive(data); 13. //Invoke method and invokeAndKeepAlive two methods of choice } 14. }

OnWXScrollListener

如果想要拿到instance滚动的信息,需要在WXSDKInstance上注册registerOnWXScrollListener ,详细参数见OnWXScrollListener

其它的一些接口介绍

设置instance显示的大小

使用mWXSDKInstance.setSize()来改变instance容器显示的大小

降级

Weex在开发过程中,会不断增加新的feature,但是这些feature可能在老版本上不兼容。这种情况下,native可以在IWXRenderListener的onException中进行判断,如果错误信息是 "|"格式. 并且分割后,"|"前第一个字符串等于1,这时候native可以直接降级到h5页面或者提示用户当前版本不支持。