Search in sources :

Example 41 with WXComponent

use of com.taobao.weex.ui.component.WXComponent in project incubator-weex by apache.

the class Statements method copyComponentTree.

/**
 * recursive copy component,
 */
private static final WXComponent copyComponentTree(WXComponent source, WXVContainer parent) {
    WXDomObject node = (WXDomObject) source.getDomObject();
    WXComponent component = WXComponentFactory.newInstance(source.getInstance(), node, parent);
    if (source instanceof WXVContainer) {
        WXVContainer container = (WXVContainer) source;
        WXVContainer childParent = (WXVContainer) component;
        WXDomObject childParentNode = (WXDomObject) childParent.getDomObject();
        int count = container.getChildCount();
        for (int i = 0; i < count; ++i) {
            WXComponent child = container.getChild(i);
            if (child != null) {
                WXComponent targetChild = copyComponentTree(child, childParent);
                childParent.addChild(targetChild);
                childParentNode.add((WXDomObject) targetChild.getDomObject(), -1);
            }
        }
    }
    // copy info need be sync
    if (source.isWaste()) {
        component.setWaste(true);
    }
    return component;
}
Also used : WXVContainer(com.taobao.weex.ui.component.WXVContainer) WXDomObject(com.taobao.weex.dom.WXDomObject) WXComponent(com.taobao.weex.ui.component.WXComponent)

Example 42 with WXComponent

use of com.taobao.weex.ui.component.WXComponent in project incubator-weex by apache.

the class BasicListComponent method onCreateViewHolder.

/**
 * Create an instance of {@link ListBaseViewHolder} for the given viewType (not for the given
 * index). This  markComponentUsable();method will look up for the first component that fits the viewType requirement and
 * doesn't be used. Then create the certain type of view, detach the view f[rom the component.
 *
 * @param parent   the ViewGroup into which the new view will be inserted
 * @param viewType the type of the new view
 * @return the created view holder.
 */
@Override
public ListBaseViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
    if (mChildren != null) {
        if (mViewTypes == null)
            return createVHForFakeComponent(viewType);
        ArrayList<WXComponent> mTypes = mViewTypes.get(viewType);
        checkRecycledViewPool(viewType);
        if (mTypes == null)
            return createVHForFakeComponent(viewType);
        for (int i = 0; i < mTypes.size(); i++) {
            WXComponent component = mTypes.get(i);
            if (component == null || component.isUsing()) {
                continue;
            }
            if (component.getDomObject() != null && component.getDomObject().isFixed()) {
                return createVHForFakeComponent(viewType);
            } else {
                if (component instanceof WXCell) {
                    if (component.getRealView() != null) {
                        return new ListBaseViewHolder(component, viewType);
                    } else {
                        ((WXCell) component).lazy(false);
                        component.createView();
                        component.applyLayoutAndEvent(component);
                        return new ListBaseViewHolder(component, viewType);
                    }
                } else if (component instanceof WXBaseRefresh) {
                    return createVHForRefreshComponent(viewType);
                } else {
                    WXLogUtils.e(TAG, "List cannot include element except cell、header、fixed、refresh and loading");
                    return createVHForFakeComponent(viewType);
                }
            }
        }
    }
    if (WXEnvironment.isApkDebugable()) {
        WXLogUtils.e(TAG, "Cannot find request viewType: " + viewType);
    }
    return createVHForFakeComponent(viewType);
}
Also used : WXComponent(com.taobao.weex.ui.component.WXComponent) WXBaseRefresh(com.taobao.weex.ui.component.WXBaseRefresh) Point(android.graphics.Point) ListBaseViewHolder(com.taobao.weex.ui.view.listview.adapter.ListBaseViewHolder)

Example 43 with WXComponent

use of com.taobao.weex.ui.component.WXComponent in project incubator-weex by apache.

the class BasicListComponent method scrollTo.

@Override
public void scrollTo(WXComponent component, Map<String, Object> options) {
    float offsetFloat = 0;
    boolean smooth = true;
    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());
            }
        }
    }
    final int offset = (int) offsetFloat;
    T bounceRecyclerView = getHostView();
    if (bounceRecyclerView == null) {
        return;
    }
    WXComponent parent = component;
    WXCell cell = null;
    while (parent != null) {
        if (parent instanceof WXCell) {
            cell = (WXCell) parent;
            break;
        }
        parent = parent.getParent();
    }
    if (cell != null) {
        final int pos = mChildren.indexOf(cell);
        if (pos == -1) {
            // Invalid position
            return;
        }
        final WXRecyclerView view = bounceRecyclerView.getInnerView();
        view.scrollTo(smooth, pos, offset, getOrientation());
    }
}
Also used : WXComponent(com.taobao.weex.ui.component.WXComponent) WXRecyclerView(com.taobao.weex.ui.view.listview.WXRecyclerView) Point(android.graphics.Point)

Example 44 with WXComponent

use of com.taobao.weex.ui.component.WXComponent in project incubator-weex by apache.

the class BasicListComponent method findComponentByAnchorName.

@Nullable
private WXComponent findComponentByAnchorName(@NonNull WXComponent root, @NonNull String anchorName) {
    long start = 0;
    if (WXEnvironment.isApkDebugable()) {
        start = System.currentTimeMillis();
    }
    Deque<WXComponent> deque = new ArrayDeque<>();
    deque.add(root);
    while (!deque.isEmpty()) {
        WXComponent curComponent = deque.removeFirst();
        ImmutableDomObject object = curComponent.getDomObject();
        if (object != null) {
            String isAnchorSet = WXUtils.getString(object.getAttrs().get(anchorName), null);
            // hit
            if (isAnchorSet != null && isAnchorSet.equals("true")) {
                if (WXEnvironment.isApkDebugable()) {
                    WXLogUtils.d("dragPerf", "findComponentByAnchorName time: " + (System.currentTimeMillis() - start) + "ms");
                }
                return curComponent;
            }
        }
        if (curComponent instanceof WXVContainer) {
            WXVContainer container = (WXVContainer) curComponent;
            for (int i = 0, len = container.childCount(); i < len; i++) {
                WXComponent child = container.getChild(i);
                deque.add(child);
            }
        }
    }
    if (WXEnvironment.isApkDebugable()) {
        WXLogUtils.d("dragPerf", "findComponentByAnchorName elapsed time: " + (System.currentTimeMillis() - start) + "ms");
    }
    return null;
}
Also used : WXVContainer(com.taobao.weex.ui.component.WXVContainer) WXComponent(com.taobao.weex.ui.component.WXComponent) ImmutableDomObject(com.taobao.weex.dom.ImmutableDomObject) ArrayDeque(java.util.ArrayDeque) Point(android.graphics.Point) Nullable(android.support.annotation.Nullable)

Example 45 with WXComponent

use of com.taobao.weex.ui.component.WXComponent in project incubator-weex by apache.

the class BasicListComponent method onBindViewHolder.

/**
 * Bind the component of the position to the holder. Then flush the view.
 *
 * @param holder   viewHolder, which holds reference to the view
 * @param position position of component in list
 */
@Override
public void onBindViewHolder(final ListBaseViewHolder holder, int position) {
    if (holder == null)
        return;
    holder.setComponentUsing(true);
    WXComponent component = getChild(position);
    if (component == null || (component instanceof WXRefresh) || (component instanceof WXLoading) || (component.getDomObject() != null && component.getDomObject().isFixed())) {
        if (WXEnvironment.isApkDebugable()) {
            WXLogUtils.d(TAG, "Bind WXRefresh & WXLoading " + holder);
        }
        if (component instanceof WXBaseRefresh && holder.getView() != null && component.getDomObject() != null && (component.getDomObject().getAttrs().get("holderBackground") != null)) {
            Object holderBackground = component.getDomObject().getAttrs().get("holderBackground");
            int color = WXResourceUtils.getColor(holderBackground.toString(), Color.WHITE);
            holder.getView().setBackgroundColor(color);
            holder.getView().setVisibility(View.VISIBLE);
            holder.getView().postInvalidate();
        }
        return;
    }
    if (holder.getComponent() != null && holder.getComponent() instanceof WXCell) {
        if (holder.isRecycled()) {
            holder.bindData(component);
            component.onRenderFinish(STATE_UI_FINISH);
        }
        if (mDragHelper == null || !mDragHelper.isDraggable()) {
            return;
        }
        mTriggerType = (mTriggerType == null) ? DEFAULT_TRIGGER_TYPE : mTriggerType;
        WXCell cell = (WXCell) holder.getComponent();
        boolean isExcluded = DEFAULT_EXCLUDED;
        if (cell.getDomObject() != null) {
            WXAttr cellAttrs = cell.getDomObject().getAttrs();
            isExcluded = WXUtils.getBoolean(cellAttrs.get(EXCLUDED), DEFAULT_EXCLUDED);
        }
        mDragHelper.setDragExcluded(holder, isExcluded);
        // NOTICE: event maybe consumed by other views
        if (DragTriggerType.PAN.equals(mTriggerType)) {
            mDragHelper.setLongPressDragEnabled(false);
            WXComponent anchorComponent = findComponentByAnchorName(cell, DRAG_ANCHOR);
            if (anchorComponent != null && anchorComponent.getHostView() != null && !isExcluded) {
                View anchor = anchorComponent.getHostView();
                anchor.setOnTouchListener(new View.OnTouchListener() {

                    @Override
                    public boolean onTouch(View v, MotionEvent event) {
                        if (MotionEventCompat.getActionMasked(event) == MotionEvent.ACTION_DOWN) {
                            mDragHelper.startDrag(holder);
                        }
                        return true;
                    }
                });
            } else {
                if (WXEnvironment.isApkDebugable()) {
                    if (!isExcluded) {
                        WXLogUtils.e(TAG, "[error] onBindViewHolder: the anchor component or view is not found");
                    } else {
                        WXLogUtils.d(TAG, "onBindViewHolder: position " + position + " is drag excluded");
                    }
                }
            }
        } else if (DragTriggerType.LONG_PRESS.equals(mTriggerType)) {
            mDragHelper.setLongPressDragEnabled(true);
        }
    }
}
Also used : WXComponent(com.taobao.weex.ui.component.WXComponent) WXBaseRefresh(com.taobao.weex.ui.component.WXBaseRefresh) WXLoading(com.taobao.weex.ui.component.WXLoading) WXRecyclerView(com.taobao.weex.ui.view.listview.WXRecyclerView) View(android.view.View) RecyclerView(android.support.v7.widget.RecyclerView) BounceRecyclerView(com.taobao.weex.ui.view.refresh.wrapper.BounceRecyclerView) WXRefresh(com.taobao.weex.ui.component.WXRefresh) Point(android.graphics.Point) MotionEvent(android.view.MotionEvent) WXDomObject(com.taobao.weex.dom.WXDomObject) ImmutableDomObject(com.taobao.weex.dom.ImmutableDomObject) WXAttr(com.taobao.weex.dom.WXAttr)

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