use of com.taobao.weex.ui.view.refresh.wrapper.BounceRecyclerView in project incubator-weex by apache.
the class BasicListComponent method onBeforeScroll.
@Override
public void onBeforeScroll(int dx, int dy) {
T bounceRecyclerView = getHostView();
if (mStickyMap == null || bounceRecyclerView == null) {
return;
}
Map<String, WXComponent> stickyMap = mStickyMap.get(getRef());
if (stickyMap == null) {
return;
}
Iterator<Map.Entry<String, WXComponent>> iterator = stickyMap.entrySet().iterator();
Map.Entry<String, WXComponent> entry;
WXComponent stickyComponent;
int currentStickyPos = -1;
while (iterator.hasNext()) {
entry = iterator.next();
stickyComponent = entry.getValue();
if (stickyComponent != null && stickyComponent.getDomObject() != null && stickyComponent instanceof WXCell) {
WXCell cell = (WXCell) stickyComponent;
if (cell.getHostView() == null) {
return;
}
int[] location = new int[2];
stickyComponent.getHostView().getLocationOnScreen(location);
int[] parentLocation = new int[2];
stickyComponent.getParentScroller().getView().getLocationOnScreen(parentLocation);
int top = location[1] - parentLocation[1];
RecyclerView.LayoutManager layoutManager;
boolean beforeFirstVisibleItem = false;
boolean removeOldSticky = false;
layoutManager = getHostView().getInnerView().getLayoutManager();
if (layoutManager instanceof LinearLayoutManager || layoutManager instanceof GridLayoutManager) {
int firstVisiblePosition = ((LinearLayoutManager) layoutManager).findFirstVisibleItemPosition();
int lastVisiblePosition = ((LinearLayoutManager) layoutManager).findLastVisibleItemPosition();
int pos = mChildren.indexOf(cell);
cell.setScrollPositon(pos);
if (pos <= firstVisiblePosition || (cell.getStickyOffset() > 0 && firstVisiblePosition < pos && pos <= lastVisiblePosition && top <= cell.getStickyOffset())) {
beforeFirstVisibleItem = true;
if (pos > currentStickyPos) {
currentStickyPos = pos;
}
} else {
removeOldSticky = true;
}
} else if (layoutManager instanceof StaggeredGridLayoutManager) {
int[] firstItems = new int[3];
int firstVisiblePosition = ((StaggeredGridLayoutManager) layoutManager).findFirstVisibleItemPositions(firstItems)[0];
int lastVisiblePosition = ((StaggeredGridLayoutManager) layoutManager).findLastVisibleItemPositions(firstItems)[0];
int pos = mChildren.indexOf(cell);
if (pos <= firstVisiblePosition || (cell.getStickyOffset() > 0 && firstVisiblePosition < pos && pos <= lastVisiblePosition && top <= cell.getStickyOffset())) {
beforeFirstVisibleItem = true;
if (pos > currentStickyPos) {
currentStickyPos = pos;
}
} else {
removeOldSticky = true;
}
}
boolean showSticky = beforeFirstVisibleItem && cell.getLocationFromStart() >= 0 && top <= cell.getStickyOffset() && dy >= 0;
boolean removeSticky = cell.getLocationFromStart() <= cell.getStickyOffset() && top > cell.getStickyOffset() && dy <= 0;
if (showSticky) {
bounceRecyclerView.notifyStickyShow(cell);
} else if (removeSticky || removeOldSticky) {
bounceRecyclerView.notifyStickyRemove(cell);
}
cell.setLocationFromStart(top);
}
}
if (currentStickyPos >= 0) {
bounceRecyclerView.updateStickyView(currentStickyPos);
} else {
if (bounceRecyclerView instanceof BounceRecyclerView) {
((BounceRecyclerView) bounceRecyclerView).getStickyHeaderHelper().clearStickyHeaders();
}
}
}
use of com.taobao.weex.ui.view.refresh.wrapper.BounceRecyclerView 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.refresh.wrapper.BounceRecyclerView 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