Search in sources :

Example 1 with WXRefresh

use of com.taobao.weex.ui.component.WXRefresh in project weex-example by KalicyZhou.

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 WXListComponent
   */
@Override
public void onBindViewHolder(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);
        }
        return;
    }
    if (holder.getComponent() != null && holder.getComponent() instanceof WXCell) {
        holder.getComponent().bindData(component);
    //              holder.getComponent().refreshData(component);
    }
}
Also used : WXComponent(com.taobao.weex.ui.component.WXComponent) WXLoading(com.taobao.weex.ui.component.WXLoading) WXRefresh(com.taobao.weex.ui.component.WXRefresh)

Example 2 with WXRefresh

use of com.taobao.weex.ui.component.WXRefresh 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)

Example 3 with WXRefresh

use of com.taobao.weex.ui.component.WXRefresh in project weex-example by KalicyZhou.

the class WXListComponent method createChildViewAt.

@Override
public void createChildViewAt(int index) {
    int indexToCreate = index;
    if (indexToCreate < 0) {
        indexToCreate = childCount() - 1;
        if (indexToCreate < 0) {
            return;
        }
    }
    final WXComponent child = getChild(indexToCreate);
    if (child instanceof WXBaseRefresh) {
        child.createView();
        if (child instanceof WXRefresh) {
            getHostView().setOnRefreshListener((WXRefresh) child);
            getHostView().postDelayed(new Runnable() {

                @Override
                public void run() {
                    getHostView().setHeaderView(child);
                }
            }, 100);
        } else if (child instanceof WXLoading) {
            getHostView().setOnLoadingListener((WXLoading) child);
            getHostView().postDelayed(new Runnable() {

                @Override
                public void run() {
                    getHostView().setFooterView(child);
                }
            }, 100);
        }
    } else {
        super.createChildViewAt(indexToCreate);
    }
}
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 4 with WXRefresh

use of com.taobao.weex.ui.component.WXRefresh 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)

Aggregations

WXComponent (com.taobao.weex.ui.component.WXComponent)4 WXLoading (com.taobao.weex.ui.component.WXLoading)4 WXRefresh (com.taobao.weex.ui.component.WXRefresh)4 WXBaseRefresh (com.taobao.weex.ui.component.WXBaseRefresh)3 Point (android.graphics.Point)1 RecyclerView (android.support.v7.widget.RecyclerView)1 MotionEvent (android.view.MotionEvent)1 View (android.view.View)1 ImmutableDomObject (com.taobao.weex.dom.ImmutableDomObject)1 WXAttr (com.taobao.weex.dom.WXAttr)1 WXDomObject (com.taobao.weex.dom.WXDomObject)1 WXRecyclerView (com.taobao.weex.ui.view.listview.WXRecyclerView)1 BounceRecyclerView (com.taobao.weex.ui.view.refresh.wrapper.BounceRecyclerView)1