Search in sources :

Example 86 with WXComponent

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);
    }
}
Also used : WXComponent(com.taobao.weex.ui.component.WXComponent) ArrayMap(android.support.v4.util.ArrayMap) Map(java.util.Map) HashMap(java.util.HashMap) Point(android.graphics.Point) AppearanceHelper(com.taobao.weex.ui.component.AppearanceHelper)

Example 87 with WXComponent

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);
        }
    }
}
Also used : WXComponent(com.taobao.weex.ui.component.WXComponent) WXBaseRefresh(com.taobao.weex.ui.component.WXBaseRefresh) WXLoading(com.taobao.weex.ui.component.WXLoading) WXRefresh(com.taobao.weex.ui.component.WXRefresh)

Example 88 with WXComponent

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();
        }
    }
}
Also used : WXComponent(com.taobao.weex.ui.component.WXComponent) BounceRecyclerView(com.taobao.weex.ui.view.refresh.wrapper.BounceRecyclerView) StaggeredGridLayoutManager(android.support.v7.widget.StaggeredGridLayoutManager) LinearLayoutManager(android.support.v7.widget.LinearLayoutManager) Point(android.graphics.Point) GridLayoutManager(android.support.v7.widget.GridLayoutManager) StaggeredGridLayoutManager(android.support.v7.widget.StaggeredGridLayoutManager) WXRecyclerView(com.taobao.weex.ui.view.listview.WXRecyclerView) RecyclerView(android.support.v7.widget.RecyclerView) BounceRecyclerView(com.taobao.weex.ui.view.refresh.wrapper.BounceRecyclerView) ArrayMap(android.support.v4.util.ArrayMap) Map(java.util.Map) HashMap(java.util.HashMap)

Example 89 with WXComponent

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);
}
Also used : WXComponent(com.taobao.weex.ui.component.WXComponent) Point(android.graphics.Point)

Example 90 with WXComponent

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;
}
Also used : WXComponent(com.taobao.weex.ui.component.WXComponent) HashMap(java.util.HashMap) WXDomObject(com.taobao.weex.dom.WXDomObject) ImmutableDomObject(com.taobao.weex.dom.ImmutableDomObject) Point(android.graphics.Point)

Aggregations

WXComponent (com.taobao.weex.ui.component.WXComponent)101 Point (android.graphics.Point)21 WXDomObject (com.taobao.weex.dom.WXDomObject)20 WXVContainer (com.taobao.weex.ui.component.WXVContainer)19 HashMap (java.util.HashMap)13 View (android.view.View)9 WXSDKInstanceTest (com.taobao.weex.WXSDKInstanceTest)9 WXRecyclerView (com.taobao.weex.ui.view.listview.WXRecyclerView)9 Map (java.util.Map)9 Test (org.junit.Test)9 ArrayMap (android.support.v4.util.ArrayMap)8 RecyclerView (android.support.v7.widget.RecyclerView)8 JSONObject (com.alibaba.fastjson.JSONObject)8 WXSDKInstance (com.taobao.weex.WXSDKInstance)8 ComponentTest (com.taobao.weex.ui.component.ComponentTest)8 WXDivTest (com.taobao.weex.ui.component.WXDivTest)8 Scrollable (com.taobao.weex.ui.component.Scrollable)6 WXBaseRefresh (com.taobao.weex.ui.component.WXBaseRefresh)6 WXHeaderTest (com.taobao.weex.ui.component.WXHeaderTest)6 AppearanceHelper (com.taobao.weex.ui.component.AppearanceHelper)5