use of com.taobao.weex.IWXRenderListener in project weiui by kuaifan.
the class Tabbar method addWXSDKView.
/**
* 添加、刷新 浏览器页面
* @param tabName
*/
private void addWXSDKView(String tabName) {
WXSDKBean sdkBean = WXSDKList.get(tabName);
if (sdkBean == null || !sdkBean.getType().equals("urlView")) {
return;
}
String url = String.valueOf(sdkBean.getView());
if (url == null) {
return;
}
//
if (sdkBean.getInstance() != null) {
sdkBean.getInstance().registerRenderListener(null);
sdkBean.getInstance().destroy();
}
//
sdkBean.getProgress().setVisibility(View.VISIBLE);
sdkBean.setInstance(new WXSDKInstance(getContext()));
sdkBean.getInstance().registerRenderListener(new IWXRenderListener() {
@Override
public void onViewCreated(WXSDKInstance instance, View view) {
sdkBean.getProgress().setVisibility(View.GONE);
sdkBean.getContainer().removeAllViews();
sdkBean.getContainer().addView(view);
//
if (getDomObject().getEvents().contains(weiuiConstants.Event.VIEW_CREATED)) {
Map<String, Object> data = new HashMap<>();
data.put("tabName", tabName);
data.put("url", url);
fireEvent(weiuiConstants.Event.VIEW_CREATED, data);
}
}
@Override
public void onRenderSuccess(WXSDKInstance instance, int width, int height) {
}
@Override
public void onRefreshSuccess(WXSDKInstance instance, int width, int height) {
}
@Override
public void onException(WXSDKInstance instance, String errCode, String msg) {
}
});
//
sdkBean.getInstance().registerOnWXScrollListener(new OnWXScrollListener() {
@Override
public void onScrolled(View view, int x, int y) {
if (getDomObject().getEvents().contains(weiuiConstants.Event.SCROLLED)) {
Map<String, Object> data = new HashMap<>();
data.put("tabName", tabName);
data.put("x", x);
data.put("y", y);
fireEvent(weiuiConstants.Event.SCROLLED, data);
}
}
@Override
public void onScrollStateChanged(View view, int x, int y, int newState) {
if (getDomObject().getEvents().contains(weiuiConstants.Event.SCROLL_STATE_CHANGED)) {
Map<String, Object> data = new HashMap<>();
data.put("tabName", tabName);
data.put("x", x);
data.put("y", y);
data.put("newState", newState);
fireEvent(weiuiConstants.Event.SCROLL_STATE_CHANGED, data);
}
if (sdkBean.getSwipeRefreshEnable()) {
if (y == 0) {
sdkBean.getSwipeRefresh().setEnabled(true);
} else {
sdkBean.getSwipeRefresh().setEnabled(false);
}
}
}
});
//
Map<String, Object> options = new HashMap<>();
options.put(WXSDKInstance.BUNDLE_URL, url);
sdkBean.getInstance().renderByUrl("Tabbar:" + tabName, url, options, null, WXRenderStrategy.APPEND_ASYNC);
}
Aggregations