use of vip.kuaifan.weiui.ui.component.tabbar.bean.WXSDKBean 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);
}
use of vip.kuaifan.weiui.ui.component.tabbar.bean.WXSDKBean in project weiui by kuaifan.
the class Tabbar method addPageView.
/**
* 添加页面
* @param barBean
*/
private void addPageView(TabbarBean barBean) {
View view = ((Activity) getContext()).getLayoutInflater().inflate(R.layout.layout_weiui_tabbar_page, null);
SwipeRefreshLayout v_swipeRefresh = view.findViewById(R.id.v_swipeRefresh);
FrameLayout v_container = view.findViewById(R.id.v_container);
ProgressBar v_progress = view.findViewById(R.id.v_progress);
//
WXSDKBean sdkBean = new WXSDKBean();
sdkBean.setSwipeRefresh(v_swipeRefresh);
sdkBean.setContainer(v_container);
sdkBean.setProgress(v_progress);
sdkBean.setView(barBean.getView());
if (barBean.getView() instanceof String) {
sdkBean.setType("urlView");
WXSDKList.put(barBean.getTabName(), sdkBean);
addWXSDKView(barBean.getTabName());
} else if (barBean.getView() instanceof TabbarPageView) {
sdkBean.setType("pageView");
WXSDKList.put(barBean.getTabName(), sdkBean);
addWXPageView(barBean.getTabName());
}
//
if (getDomObject().getEvents().contains(weiuiConstants.Event.REFRESH_LISTENER)) {
sdkBean.getSwipeRefresh().setColorSchemeResources(android.R.color.holo_blue_light, android.R.color.holo_red_light, android.R.color.holo_orange_light, android.R.color.holo_green_light);
sdkBean.getSwipeRefresh().setOnRefreshListener(() -> {
Map<String, Object> data = new HashMap<>();
data.put("tabName", barBean.getTabName());
data.put("position", getTabPosition(barBean.getTabName()));
fireEvent(weiuiConstants.Event.REFRESH_LISTENER, data);
});
sdkBean.setSwipeRefreshEnable(true);
} else {
sdkBean.setSwipeRefreshEnable(false);
sdkBean.getSwipeRefresh().setEnabled(false);
}
//
mTabEntity.add(new TabbarEntity(barBean));
mViewList.add(view);
mTabPagerAdapter.setListViews(mViewList);
mTabPagerAdapter.notifyDataSetChanged();
}
use of vip.kuaifan.weiui.ui.component.tabbar.bean.WXSDKBean in project weiui by kuaifan.
the class Tabbar method addWXPageView.
/**
* 添加子页面
* @param tabName
*/
private void addWXPageView(String tabName) {
WXSDKBean sdkBean = WXSDKList.get(tabName);
if (sdkBean == null || !sdkBean.getType().equals("pageView")) {
return;
}
TabbarPageView view = (TabbarPageView) sdkBean.getView();
if (view == null) {
return;
}
//
ViewGroup parentViewGroup = (ViewGroup) view.getParent();
if (parentViewGroup != null) {
parentViewGroup.removeView(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", null);
fireEvent(weiuiConstants.Event.VIEW_CREATED, data);
}
}
use of vip.kuaifan.weiui.ui.component.tabbar.bean.WXSDKBean in project weiui by kuaifan.
the class Tabbar method goUrl.
/**
* 跳转页面
* @param tabName
* @param url
*/
@JSMethod
public void goUrl(String tabName, String url) {
WXSDKBean bean = WXSDKList.get(tabName);
if (bean != null) {
bean.setView(url);
WXSDKList.put(tabName, bean);
addWXSDKView(tabName);
}
}
Aggregations