Search in sources :

Example 1 with IWXRenderListener

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);
}
Also used : HashMap(java.util.HashMap) OnWXScrollListener(com.taobao.weex.common.OnWXScrollListener) View(android.view.View) WXSDKBean(vip.kuaifan.weiui.ui.component.tabbar.bean.WXSDKBean) WXSDKInstance(com.taobao.weex.WXSDKInstance) IWXRenderListener(com.taobao.weex.IWXRenderListener) WXDomObject(com.taobao.weex.dom.WXDomObject) JSONObject(com.alibaba.fastjson.JSONObject) HashMap(java.util.HashMap) Map(java.util.Map)

Aggregations

View (android.view.View)1 JSONObject (com.alibaba.fastjson.JSONObject)1 IWXRenderListener (com.taobao.weex.IWXRenderListener)1 WXSDKInstance (com.taobao.weex.WXSDKInstance)1 OnWXScrollListener (com.taobao.weex.common.OnWXScrollListener)1 WXDomObject (com.taobao.weex.dom.WXDomObject)1 HashMap (java.util.HashMap)1 Map (java.util.Map)1 WXSDKBean (vip.kuaifan.weiui.ui.component.tabbar.bean.WXSDKBean)1