use of com.taobao.weex.ui.component.WXComponent in project incubator-weex by apache.
the class BasicListComponent method relocateAppearanceHelper.
private void relocateAppearanceHelper() {
Iterator<Map.Entry<String, AppearanceHelper>> iterator = mAppearComponents.entrySet().iterator();
while (iterator.hasNext()) {
Map.Entry<String, AppearanceHelper> item = iterator.next();
AppearanceHelper value = item.getValue();
WXComponent dChild = findDirectListChild(value.getAwareChild());
int index = mChildren.indexOf(dChild);
value.setCellPosition(index);
}
}
use of com.taobao.weex.ui.component.WXComponent in project incubator-weex by apache.
the class WXListComponent method createChildViewAt.
@Override
public void createChildViewAt(int index) {
Pair<WXComponent, Integer> ret = rearrangeIndexAndGetChild(index);
if (ret.first != null) {
final WXComponent child = getChild(ret.second);
if (child instanceof WXBaseRefresh) {
child.createView();
if (child instanceof WXRefresh) {
getHostView().setOnRefreshListener((WXRefresh) child);
getHostView().postDelayed(WXThread.secure(new Runnable() {
@Override
public void run() {
getHostView().setHeaderView(child);
}
}), 100);
} else if (child instanceof WXLoading) {
getHostView().setOnLoadingListener((WXLoading) child);
getHostView().postDelayed(WXThread.secure(new Runnable() {
@Override
public void run() {
getHostView().setFooterView(child);
}
}), 100);
}
} else {
super.createChildViewAt(ret.second);
}
}
}
use of com.taobao.weex.ui.component.WXComponent 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.component.WXComponent in project incubator-weex by apache.
the class BasicListComponent method unBindViewType.
private void unBindViewType(WXComponent component) {
int id = generateViewType(component);
if (mViewTypes == null)
return;
ArrayList<WXComponent> mTypes = mViewTypes.get(id);
if (mTypes == null)
return;
mTypes.remove(component);
}
use of com.taobao.weex.ui.component.WXComponent in project incubator-weex by apache.
the class BasicListComponent method getScrollEvent.
public Map<String, Object> getScrollEvent(RecyclerView recyclerView, int offsetX, int offsetY) {
if (getOrientation() == Constants.Orientation.VERTICAL) {
offsetY = -calcContentOffset(recyclerView);
}
int contentWidth = recyclerView.getMeasuredWidth() + recyclerView.computeHorizontalScrollRange();
int contentHeight = 0;
for (int i = 0; i < getChildCount(); i++) {
WXComponent child = getChild(i);
if (child != null) {
contentHeight += child.getLayoutHeight();
}
}
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().getInstanceViewPortWidth()));
contentSize.put(Constants.Name.HEIGHT, WXViewUtils.getWebPxByWidth(contentHeight, getInstance().getInstanceViewPortWidth()));
contentOffset.put(Constants.Name.X, -WXViewUtils.getWebPxByWidth(offsetX, getInstance().getInstanceViewPortWidth()));
contentOffset.put(Constants.Name.Y, -WXViewUtils.getWebPxByWidth(offsetY, getInstance().getInstanceViewPortWidth()));
event.put(Constants.Name.CONTENT_SIZE, contentSize);
event.put(Constants.Name.CONTENT_OFFSET, contentOffset);
return event;
}
Aggregations