use of com.taobao.weex.ui.view.listview.WXRecyclerView in project weex-example by KalicyZhou.
the class BasicListComponent method addEvent.
@Override
public void addEvent(String type) {
super.addEvent(type);
if (Constants.Event.SCROLL.equals(type) && getHostView() != null && getHostView().getInnerView() != null) {
WXRecyclerView innerView = getHostView().getInnerView();
innerView.addOnScrollListener(new RecyclerView.OnScrollListener() {
@Override
public void onScrolled(RecyclerView recyclerView, int dx, int dy) {
super.onScrolled(recyclerView, dx, dy);
int offsetX = recyclerView.computeHorizontalScrollOffset();
int offsetY = recyclerView.computeVerticalScrollOffset();
if (shouldReport(offsetX, offsetY)) {
int contentWidth = recyclerView.getMeasuredWidth() + recyclerView.computeHorizontalScrollRange();
int contentHeight = recyclerView.computeVerticalScrollRange();
Map<String, Object> event = new HashMap<>(2);
Map<String, Object> contentSize = new HashMap<>(2);
Map<String, Object> contentOffset = new HashMap<>(2);
contentSize.put(Constants.Name.WIDTH, WXViewUtils.getWebPxByWidth(contentWidth, getInstance().getViewPortWidth()));
contentSize.put(Constants.Name.HEIGHT, WXViewUtils.getWebPxByWidth(contentHeight, getInstance().getViewPortWidth()));
contentOffset.put(Constants.Name.X, -WXViewUtils.getWebPxByWidth(offsetX, getInstance().getViewPortWidth()));
contentOffset.put(Constants.Name.Y, -WXViewUtils.getWebPxByWidth(offsetY, getInstance().getViewPortWidth()));
event.put(Constants.Name.CONTENT_SIZE, contentSize);
event.put(Constants.Name.CONTENT_OFFSET, contentOffset);
fireEvent(Constants.Event.SCROLL, event);
}
}
});
}
}
use of com.taobao.weex.ui.view.listview.WXRecyclerView in project weex-example by KalicyZhou.
the class BasicListComponent method setScrollable.
@WXComponentProp(name = Constants.Name.SCROLLABLE)
public void setScrollable(boolean scrollable) {
this.isScrollable = scrollable;
WXRecyclerView inner = getHostView().getInnerView();
if (inner != null) {
inner.setScrollable(scrollable);
}
}
use of com.taobao.weex.ui.view.listview.WXRecyclerView in project incubator-weex by apache.
the class BasicListComponent method onHostViewInitialized.
@Override
protected void onHostViewInitialized(T host) {
super.onHostViewInitialized(host);
WXRecyclerView recyclerView = host.getInnerView();
if (recyclerView == null || recyclerView.getAdapter() == null) {
WXLogUtils.e(TAG, "RecyclerView is not found or Adapter is not bound");
return;
}
if (WXUtils.getBoolean(getDomObject().getAttrs().get("prefetchGapDisable"), false)) {
if (recyclerView.getLayoutManager() != null) {
recyclerView.getLayoutManager().setItemPrefetchEnabled(false);
}
}
if (mChildren == null) {
WXLogUtils.e(TAG, "children is null");
return;
}
mDragHelper = new DefaultDragHelper(mChildren, recyclerView, new EventTrigger() {
@Override
public void triggerEvent(String type, Map<String, Object> args) {
fireEvent(type, args);
}
});
mTriggerType = getTriggerType(getDomObject());
}
use of com.taobao.weex.ui.view.listview.WXRecyclerView in project incubator-weex by apache.
the class BasicListComponent method scrollTo.
@Override
public void scrollTo(WXComponent component, Map<String, Object> options) {
float offsetFloat = 0;
boolean smooth = true;
if (options != null) {
String offsetStr = options.get(Constants.Name.OFFSET) == null ? "0" : options.get(Constants.Name.OFFSET).toString();
smooth = WXUtils.getBoolean(options.get(Constants.Name.ANIMATED), true);
if (offsetStr != null) {
try {
offsetFloat = WXViewUtils.getRealPxByWidth(Float.parseFloat(offsetStr), getInstance().getInstanceViewPortWidth());
} catch (Exception e) {
WXLogUtils.e("Float parseFloat error :" + e.getMessage());
}
}
}
final int offset = (int) offsetFloat;
T bounceRecyclerView = getHostView();
if (bounceRecyclerView == null) {
return;
}
WXComponent parent = component;
WXCell cell = null;
while (parent != null) {
if (parent instanceof WXCell) {
cell = (WXCell) parent;
break;
}
parent = parent.getParent();
}
if (cell != null) {
final int pos = mChildren.indexOf(cell);
if (pos == -1) {
// Invalid position
return;
}
final WXRecyclerView view = bounceRecyclerView.getInnerView();
view.scrollTo(smooth, pos, offset, getOrientation());
}
}
use of com.taobao.weex.ui.view.listview.WXRecyclerView in project incubator-weex by apache.
the class WXRecyclerTemplateList method setColumnWidth.
@WXComponentProp(name = Constants.Name.COLUMN_WIDTH)
public void setColumnWidth(int columnCount) {
if (mDomObject.getColumnWidth() != mColumnWidth) {
updateRecyclerAttr();
WXRecyclerView wxRecyclerView = getHostView().getInnerView();
wxRecyclerView.initView(getContext(), mLayoutType, mColumnCount, mColumnGap, getOrientation());
}
}
Aggregations