use of com.taobao.weex.ui.view.listview.WXRecyclerView in project incubator-weex by apache.
the class WXRecyclerTemplateList method scrollTo.
@JSMethod
public void scrollTo(int position, Map<String, Object> options) {
if (position >= 0) {
boolean smooth = true;
if (options != null) {
smooth = WXUtils.getBoolean(options.get(Constants.Name.ANIMATED), true);
}
final int pos = position;
BounceRecyclerView bounceRecyclerView = getHostView();
if (bounceRecyclerView == null) {
return;
}
final WXRecyclerView view = bounceRecyclerView.getInnerView();
view.scrollTo(smooth, pos, 0, getOrientation());
}
}
use of com.taobao.weex.ui.view.listview.WXRecyclerView in project incubator-weex by apache.
the class WXRecyclerTemplateList method setColumnGap.
@WXComponentProp(name = Constants.Name.COLUMN_GAP)
public void setColumnGap(float columnGap) throws InterruptedException {
if (mDomObject.getColumnGap() != mColumnGap) {
updateRecyclerAttr();
WXRecyclerView wxRecyclerView = getHostView().getInnerView();
wxRecyclerView.initView(getContext(), mLayoutType, mColumnCount, mColumnGap, getOrientation());
}
}
use of com.taobao.weex.ui.view.listview.WXRecyclerView in project incubator-weex by apache.
the class WXRecyclerTemplateList method addEvent.
@Override
public void addEvent(String type) {
super.addEvent(type);
if (ScrollStartEndHelper.isScrollEvent(type) && getHostView() != null && getHostView().getInnerView() != null && !mHasAddScrollEvent) {
mHasAddScrollEvent = true;
WXRecyclerView innerView = getHostView().getInnerView();
innerView.addOnScrollListener(new RecyclerView.OnScrollListener() {
private int offsetXCorrection, offsetYCorrection;
private boolean mFirstEvent = true;
@Override
public void onScrolled(RecyclerView recyclerView, int dx, int dy) {
super.onScrolled(recyclerView, dx, dy);
RecyclerView.LayoutManager layoutManager = recyclerView.getLayoutManager();
if (!layoutManager.canScrollVertically()) {
return;
}
int offsetX = recyclerView.computeHorizontalScrollOffset();
int offsetY = recyclerView.computeVerticalScrollOffset();
if (dx == 0 && dy == 0) {
offsetXCorrection = offsetX;
offsetYCorrection = offsetY;
offsetX = 0;
offsetY = 0;
} else {
offsetX = offsetX - offsetXCorrection;
offsetY = offsetY - offsetYCorrection;
}
getScrollStartEndHelper().onScrolled(offsetX, offsetY);
if (!getDomObject().getEvents().contains(Constants.Event.SCROLL)) {
return;
}
if (mFirstEvent) {
// skip first event
mFirstEvent = false;
return;
}
if (shouldReport(offsetX, offsetY)) {
fireScrollEvent(recyclerView, offsetX, offsetY);
}
}
});
}
}
use of com.taobao.weex.ui.view.listview.WXRecyclerView in project incubator-weex by apache.
the class WXRecyclerTemplateList method setScrollable.
@WXComponentProp(name = Constants.Name.SCROLLABLE)
public void setScrollable(boolean scrollable) {
WXRecyclerView inner = getHostView().getInnerView();
inner.setScrollable(scrollable);
}
use of com.taobao.weex.ui.view.listview.WXRecyclerView in project incubator-weex by apache.
the class WXRecyclerTemplateList method scrollTo.
@Override
public void scrollTo(WXComponent component, Map<String, Object> options) {
float offsetFloat = 0;
boolean smooth = true;
int position = -1;
int typeIndex = -1;
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());
}
}
position = WXUtils.getNumberInt(options.get(Constants.Name.Recycler.CELL_INDEX), -1);
typeIndex = WXUtils.getNumberInt(options.get(Constants.Name.Recycler.TYPE_INDEX), -1);
}
WXCell cell = findCell(component);
if (typeIndex >= 0) {
if (cellDataManager.listData != null && component.getRef() != null) {
int typePosition = 0;
for (int i = 0; i < cellDataManager.listData.size(); i++) {
WXCell template = getSourceTemplate(i);
if (template == null) {
continue;
}
if (cell.getRef().equals(template.getRef())) {
typePosition++;
}
if (typePosition > typeIndex) {
position = i;
break;
}
}
if (position < 0) {
position = cellDataManager.listData.size() - 1;
}
}
}
final int offset = (int) offsetFloat;
BounceRecyclerView bounceRecyclerView = getHostView();
if (bounceRecyclerView == null) {
return;
}
if (position >= 0) {
final int pos = position;
final WXRecyclerView view = bounceRecyclerView.getInnerView();
view.scrollTo(smooth, pos, offset, getOrientation());
}
}
Aggregations