Search in sources :

Example 1 with WXRecyclerDomObject

use of com.taobao.weex.dom.WXRecyclerDomObject in project incubator-weex by apache.

the class GapItemDecoration method getItemOffsets.

@Override
public void getItemOffsets(Rect outRect, View view, RecyclerView parent, RecyclerView.State state) {
    int position = parent.getChildAdapterPosition(view);
    if (position < 0) {
        return;
    }
    if (view.getLayoutParams() instanceof StaggeredGridLayoutManager.LayoutParams) {
        StaggeredGridLayoutManager.LayoutParams params = (StaggeredGridLayoutManager.LayoutParams) view.getLayoutParams();
        if (params.isFullSpan()) {
            return;
        }
        WXComponent component = listComponent.getChild(position);
        if (component instanceof WXCell) {
            WXCell cell = (WXCell) component;
            if (cell.isFixed() || cell.isSticky()) {
                return;
            }
            WXRecyclerDomObject recyclerDomObject = listComponent.getRecyclerDom();
            if (recyclerDomObject.getSpanOffsets() == null) {
                return;
            }
            float spanOffset = recyclerDomObject.getSpanOffsets()[params.getSpanIndex()];
            int spanOffsetPx = Math.round(WXViewUtils.getRealPxByWidth(spanOffset, recyclerDomObject.getViewPortWidth()));
            outRect.left = spanOffsetPx;
            outRect.right = -spanOffsetPx;
        }
    }
}
Also used : WXComponent(com.taobao.weex.ui.component.WXComponent) WXRecyclerDomObject(com.taobao.weex.dom.WXRecyclerDomObject) StaggeredGridLayoutManager(android.support.v7.widget.StaggeredGridLayoutManager)

Example 2 with WXRecyclerDomObject

use of com.taobao.weex.dom.WXRecyclerDomObject in project incubator-weex by apache.

the class WXRecyclerTemplateList method addChild.

@Override
public void addChild(WXComponent child, int index) {
    /**
     *  dom object in component is not tree, build tree
     */
    if (!(child instanceof WXCell)) {
        super.addChild(child, index);
    }
    if (child instanceof WXBaseRefresh) {
        return;
    }
    if (child instanceof WXCell) {
        if (child.getDomObject() != null && child.getDomObject().getAttrs() != null) {
            Object templateId = child.getDomObject().getAttrs().get(Constants.Name.Recycler.SLOT_TEMPLATE_CASE);
            String key = WXUtils.getString(templateId, null);
            if (getDomObject().getAttrs().containsKey(Constants.Name.Recycler.LIST_DATA_TEMPLATE_SWITCH_KEY)) {
                if (defaultTemplateCell == null) {
                    defaultTemplateCell = (WXCell) child;
                    if (!TextUtils.isEmpty(key)) {
                        defaultTemplateKey = key;
                    } else {
                        key = defaultTemplateKey;
                        child.getDomObject().getAttrs().put(Constants.Name.Recycler.SLOT_TEMPLATE_CASE, key);
                    }
                }
            } else {
                if (defaultTemplateCell == null || child.getDomObject().getAttrs().containsKey(Constants.Name.Recycler.SLOT_TEMPLATE_DEFAULT)) {
                    defaultTemplateCell = (WXCell) child;
                    if (!TextUtils.isEmpty(key)) {
                        defaultTemplateKey = key;
                    } else {
                        key = defaultTemplateKey;
                        child.getDomObject().getAttrs().put(Constants.Name.Recycler.SLOT_TEMPLATE_CASE, key);
                    }
                }
            }
            if (key != null) {
                if (child.getDomObject() instanceof WXCellDomObject && getDomObject() instanceof WXRecyclerDomObject) {
                    WXCellDomObject domObject = (WXCellDomObject) child.getDomObject();
                    domObject.setRecyclerDomObject((WXRecyclerDomObject) getDomObject());
                }
                mTemplateSources.put(key, (WXCell) child);
                renderTemplateCellWithData((WXCell) child);
                if (mTemplateViewTypes.get(key) == null) {
                    mTemplateViewTypes.put(key, mTemplateViewTypes.size());
                }
            }
        }
        notifyUpdateList();
    }
}
Also used : WXBaseRefresh(com.taobao.weex.ui.component.WXBaseRefresh) WXRecyclerDomObject(com.taobao.weex.dom.WXRecyclerDomObject) WXDomObject(com.taobao.weex.dom.WXDomObject) JSONObject(com.alibaba.fastjson.JSONObject) WXCellDomObject(com.taobao.weex.dom.WXCellDomObject) WXRecyclerDomObject(com.taobao.weex.dom.WXRecyclerDomObject) WXCellDomObject(com.taobao.weex.dom.WXCellDomObject) WXCell(com.taobao.weex.ui.component.list.WXCell)

Example 3 with WXRecyclerDomObject

use of com.taobao.weex.dom.WXRecyclerDomObject in project incubator-weex by apache.

the class WXRecyclerTemplateList method copyComponentFromSourceCell.

/**
 * copy cell component from source, init render data, and return source
 * if none data, return null
 */
public WXComponent copyComponentFromSourceCell(WXCell cell) {
    renderTemplateCellWithData(cell);
    WXCell component = (WXCell) Statements.copyComponentTree(cell);
    if (component.getDomObject() instanceof WXCellDomObject && getDomObject() instanceof WXRecyclerDomObject) {
        WXCellDomObject domObject = (WXCellDomObject) component.getDomObject();
        domObject.setRecyclerDomObject((WXRecyclerDomObject) getDomObject());
    }
    component.setRenderData(cell.getRenderData());
    return component;
}
Also used : WXRecyclerDomObject(com.taobao.weex.dom.WXRecyclerDomObject) WXCellDomObject(com.taobao.weex.dom.WXCellDomObject) WXCell(com.taobao.weex.ui.component.list.WXCell)

Example 4 with WXRecyclerDomObject

use of com.taobao.weex.dom.WXRecyclerDomObject in project incubator-weex by apache.

the class WXRecyclerTemplateList method initRecyclerTemplateList.

private void initRecyclerTemplateList(WXSDKInstance instance, WXDomObject node, WXVContainer parent) {
    if (node != null && node instanceof WXRecyclerDomObject) {
        mDomObject = (WXRecyclerDomObject) node;
        mDomObject.preCalculateCellWidth();
        mLayoutType = mDomObject.getLayoutType();
        updateRecyclerAttr();
    }
    mTemplateViewTypes = new ArrayMap<>();
    // empty view, when template was not sended
    mTemplateViewTypes.put(EMPTY_HOLDER_TEMPLATE_KEY, 0);
    mTemplateSources = new HashMap<>();
    mTemplatesCache = new ConcurrentHashMap<>();
    mStickyHelper = new TemplateStickyHelper(this);
    orientation = mDomObject.getOrientation();
    listDataTemplateKey = WXUtils.getString(getDomObject().getAttrs().get(Constants.Name.Recycler.LIST_DATA_TEMPLATE_SWITCH_KEY), Constants.Name.Recycler.SLOT_TEMPLATE_CASE);
    listDataItemKey = WXUtils.getString(getDomObject().getAttrs().get(Constants.Name.Recycler.LIST_DATA_ITEM), listDataItemKey);
    listDataIndexKey = WXUtils.getString(getDomObject().getAttrs().get(Constants.Name.Recycler.LIST_DATA_ITEM_INDEX), listDataIndexKey);
    cellDataManager = new CellDataManager(this);
    if (getDomObject().getAttrs().get(Constants.Name.Recycler.LIST_DATA) instanceof JSONArray) {
        JSONArray array = (JSONArray) getDomObject().getAttrs().get(Constants.Name.Recycler.LIST_DATA);
        if (array.size() > 0) {
            cellDataManager.listData = array;
        }
    }
    /**
     * we have separate cell with list, post add cell in dom thread ensure
     * list has layout and can archive better user experience and better load time,
     * which reduce waste cell layout when list layout changes.
     */
    if (mDomObject != null && mDomObject.getCellList() != null && mDomObject.getCellList().size() > 0) {
        Runnable runnable = new Runnable() {

            // @Override
            public void run() {
                if (isDestoryed()) {
                    return;
                }
                long start = System.currentTimeMillis();
                if (mDomObject != null && mDomObject.getCellList() != null) {
                    for (int i = 0; i < mDomObject.getCellList().size(); i++) {
                        addChild(ComponentUtils.buildTree(mDomObject.getCellList().get(i), WXRecyclerTemplateList.this));
                    }
                }
                if (WXEnvironment.isOpenDebugLog() && ENABLE_TRACE_LOG) {
                    WXLogUtils.d(TAG, "TemplateList BuildDomTree Used " + (System.currentTimeMillis() - start));
                }
            }
        };
        WXSDKManager.getInstance().getWXDomManager().post(runnable);
    }
}
Also used : WXRecyclerDomObject(com.taobao.weex.dom.WXRecyclerDomObject) JSONArray(com.alibaba.fastjson.JSONArray) Point(android.graphics.Point)

Aggregations

WXRecyclerDomObject (com.taobao.weex.dom.WXRecyclerDomObject)4 WXCellDomObject (com.taobao.weex.dom.WXCellDomObject)2 WXCell (com.taobao.weex.ui.component.list.WXCell)2 Point (android.graphics.Point)1 StaggeredGridLayoutManager (android.support.v7.widget.StaggeredGridLayoutManager)1 JSONArray (com.alibaba.fastjson.JSONArray)1 JSONObject (com.alibaba.fastjson.JSONObject)1 WXDomObject (com.taobao.weex.dom.WXDomObject)1 WXBaseRefresh (com.taobao.weex.ui.component.WXBaseRefresh)1 WXComponent (com.taobao.weex.ui.component.WXComponent)1