Search in sources :

Example 1 with WXCell

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

the class BounceRecyclerView method showSticky.

/**
   * Pop stickyView to stack
   */
private void showSticky() {
    WXCell headComponent = headComponentStack.pop();
    headComponentStack.push(headComponent);
    final View headerView = headComponent.getRealView();
    if (headerView == null)
        return;
    headerViewStack.push(headerView);
    //record translation, it should not change after transformation
    final float translationX = headerView.getTranslationX();
    final float translationY = headerView.getTranslationY();
    headComponent.removeSticky();
    post(WXThread.secure(new Runnable() {

        @Override
        public void run() {
            ViewGroup existedParent;
            if ((existedParent = (ViewGroup) headerView.getParent()) != null) {
                existedParent.removeView(headerView);
            }
            addView(headerView);
            //recover translation, sometimes it will be changed on fling
            headerView.setTranslationX(translationX);
            headerView.setTranslationY(translationY);
        }
    }));
}
Also used : ViewGroup(android.view.ViewGroup) ListComponentView(com.taobao.weex.ui.component.list.ListComponentView) WXRecyclerView(com.taobao.weex.ui.view.listview.WXRecyclerView) View(android.view.View) WXCell(com.taobao.weex.ui.component.list.WXCell)

Example 2 with WXCell

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

the class StatementTest method createVForNode.

private WXCell createVForNode() throws Exception {
    WXCell cell = new WXCell(WXSDKInstanceTest.createInstance(), new WXCellDomObject(), null, false);
    final WXDiv div = new WXDiv(WXSDKInstanceTest.createInstance(), new WXDomObject(), cell);
    cell.addChild(div);
    WXText text = new WXText(WXSDKInstanceTest.createInstance(), new WXTextDomObject(), div);
    WXStatement statement = new WXStatement();
    statement.put("[[repeat]]", ELUtils.vforBlock(JSON.parse("{\n" + "      '@expression': 'dataList',\n" + "      '@index': 'index',\n" + "      '@alias': 'item'\n" + "    }")));
    WXDomObject domObject = (WXDomObject) text.getDomObject();
    domObject.getAttrs().setStatement(statement);
    div.addChild(text);
    PowerMockito.mockStatic(WXComponentFactory.class, new Answer() {

        @Override
        public Object answer(InvocationOnMock invocation) throws Throwable {
            WXText renderNode = new WXText(WXSDKInstanceTest.createInstance(), new WXTextDomObject(), div);
            return renderNode;
        }
    });
    return cell;
}
Also used : Answer(org.mockito.stubbing.Answer) WXDiv(com.taobao.weex.ui.component.WXDiv) WXDomObject(com.taobao.weex.dom.WXDomObject) InvocationOnMock(org.mockito.invocation.InvocationOnMock) WXTextDomObject(com.taobao.weex.dom.WXTextDomObject) WXDomObject(com.taobao.weex.dom.WXDomObject) TestDomObject(com.taobao.weex.dom.TestDomObject) WXCellDomObject(com.taobao.weex.dom.WXCellDomObject) WXTextDomObject(com.taobao.weex.dom.WXTextDomObject) JSONObject(com.alibaba.fastjson.JSONObject) WXText(com.taobao.weex.ui.component.WXText) WXCellDomObject(com.taobao.weex.dom.WXCellDomObject) WXCell(com.taobao.weex.ui.component.list.WXCell) WXStatement(com.taobao.weex.dom.binding.WXStatement)

Example 3 with WXCell

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

the class StatementTest method testVFor.

@Test
public void testVFor() throws Exception {
    WXCell cell = createVForNode();
    int count = 3;
    Statements.doRender(cell, createContext(count));
    Assert.assertTrue(cell.getChildCount() == 1);
    WXDiv div = (WXDiv) cell.getChild(0);
    Assert.assertEquals(div.getChildCount(), count);
    Assert.assertNotNull(div.getChild(0).getDomObject());
    Assert.assertNotNull(((WXDomObject) div.getChild(0).getDomObject()).getAttrs().getStatement());
    Assert.assertNull(((WXDomObject) div.getChild(1).getDomObject()).getAttrs().getStatement());
    WXComponent childOne = div.getChild(0);
    WXComponent childTwo = div.getChild(1);
    WXComponent childThree = div.getChild(2);
    count = 4;
    Statements.doRender(cell, createContext(count));
    Assert.assertTrue(cell.getChildCount() == 1);
    div = (WXDiv) cell.getChild(0);
    Assert.assertTrue(div.getChildCount() == count);
    Assert.assertSame(childOne, div.getChild(0));
    Assert.assertSame(childTwo, div.getChild(1));
    Assert.assertSame(childThree, div.getChild(2));
    WXComponent childFour = div.getChild(3);
    count = 5;
    Statements.doRender(cell, createContext(count));
    Assert.assertTrue(cell.getChildCount() == 1);
    div = (WXDiv) cell.getChild(0);
    Assert.assertTrue(div.getChildCount() == count);
    Assert.assertSame(childOne, div.getChild(0));
    Assert.assertSame(childTwo, div.getChild(1));
    Assert.assertSame(childThree, div.getChild(2));
    Assert.assertSame(childFour, div.getChild(3));
    count = 3;
    Statements.doRender(cell, createContext(count));
    Assert.assertTrue(cell.getChildCount() == 1);
    div = (WXDiv) cell.getChild(0);
    Assert.assertTrue(div.getChildCount() == 5);
    Assert.assertSame(childOne, div.getChild(0));
    Assert.assertSame(childTwo, div.getChild(1));
    Assert.assertSame(childThree, div.getChild(2));
    for (int i = count; i < 5; i++) {
        Assert.assertTrue(div.getChild(i).isWaste());
    }
}
Also used : WXDiv(com.taobao.weex.ui.component.WXDiv) WXDomObject(com.taobao.weex.dom.WXDomObject) WXComponent(com.taobao.weex.ui.component.WXComponent) WXCell(com.taobao.weex.ui.component.list.WXCell) WXSDKInstanceTest(com.taobao.weex.WXSDKInstanceTest) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest) Test(org.junit.Test)

Example 4 with WXCell

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

the class WXRecyclerTemplateList method setAppearanceWatch.

private void setAppearanceWatch(WXComponent component, int event, boolean enable) {
    if (cellDataManager.listData == null || mAppearHelpers == null || TextUtils.isEmpty(component.getRef())) {
        return;
    }
    WXCell cell = findCell(component);
    int type = getCellTemplateItemType(cell);
    if (type < 0) {
        return;
    }
    List<AppearanceHelper> mAppearListeners = mAppearHelpers.get(type);
    if (mAppearListeners == null) {
        mAppearListeners = new ArrayList<>();
        mAppearHelpers.put(type, mAppearListeners);
    }
    AppearanceHelper item = null;
    for (AppearanceHelper mAppearListener : mAppearListeners) {
        if (component.getRef().equals(mAppearListener.getAwareChild().getRef())) {
            item = mAppearListener;
            break;
        }
    }
    if (item != null) {
        item.setWatchEvent(event, enable);
    } else {
        item = new AppearanceHelper(component, type);
        item.setWatchEvent(event, enable);
        mAppearListeners.add(item);
    }
}
Also used : WXCell(com.taobao.weex.ui.component.list.WXCell) Point(android.graphics.Point) AppearanceHelper(com.taobao.weex.ui.component.AppearanceHelper)

Example 5 with WXCell

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

the class WXRecyclerTemplateList method initComponentHostView.

@Override
protected BounceRecyclerView initComponentHostView(@NonNull Context context) {
    final BounceRecyclerView bounceRecyclerView = new BounceRecyclerView(context, mLayoutType, mColumnCount, mColumnGap, getOrientation());
    WXAttr attrs = getDomObject().getAttrs();
    String transforms = (String) attrs.get(Constants.Name.TRANSFORM);
    if (transforms != null) {
        bounceRecyclerView.getInnerView().addItemDecoration(RecyclerTransform.parseTransforms(getOrientation(), transforms));
    }
    mItemAnimator = bounceRecyclerView.getInnerView().getItemAnimator();
    if (attrs.get(NAME_TEMPLATE_CACHE_SIZE) != null) {
        templateCacheSize = WXUtils.getInteger(attrs.get(NAME_TEMPLATE_CACHE_SIZE), templateCacheSize);
    }
    boolean hasFixedSize = false;
    int itemViewCacheSize = 2;
    if (attrs.get(NAME_ITEM_VIEW_CACHE_SIZE) != null) {
        itemViewCacheSize = WXUtils.getNumberInt(getDomObject().getAttrs().get(NAME_ITEM_VIEW_CACHE_SIZE), itemViewCacheSize);
    }
    if (attrs.get(NAME_HAS_FIXED_SIZE) != null) {
        hasFixedSize = WXUtils.getBoolean(attrs.get(NAME_HAS_FIXED_SIZE), hasFixedSize);
    }
    RecyclerViewBaseAdapter recyclerViewBaseAdapter = new RecyclerViewBaseAdapter<>(this);
    recyclerViewBaseAdapter.setHasStableIds(true);
    bounceRecyclerView.getInnerView().setItemAnimator(null);
    if (itemViewCacheSize != 2) {
        bounceRecyclerView.getInnerView().setItemViewCacheSize(itemViewCacheSize);
    }
    if (bounceRecyclerView.getSwipeLayout() != null) {
        if (WXUtils.getBoolean(getDomObject().getAttrs().get("nestedScrollingEnabled"), false)) {
            bounceRecyclerView.getSwipeLayout().setNestedScrollingEnabled(true);
        }
    }
    bounceRecyclerView.getInnerView().setHasFixedSize(hasFixedSize);
    bounceRecyclerView.setRecyclerViewBaseAdapter(recyclerViewBaseAdapter);
    bounceRecyclerView.setOverScrollMode(View.OVER_SCROLL_NEVER);
    bounceRecyclerView.getInnerView().clearOnScrollListeners();
    bounceRecyclerView.getInnerView().addOnScrollListener(mViewOnScrollListener);
    bounceRecyclerView.getInnerView().addOnScrollListener(new RecyclerView.OnScrollListener() {

        @Override
        public void onScrollStateChanged(RecyclerView recyclerView, int newState) {
            super.onScrollStateChanged(recyclerView, newState);
            List<OnWXScrollListener> listeners = getInstance().getWXScrollListeners();
            if (listeners != null && listeners.size() > 0) {
                for (OnWXScrollListener listener : listeners) {
                    if (listener != null) {
                        View topView = recyclerView.getChildAt(0);
                        if (topView != null) {
                            int y = topView.getTop();
                            listener.onScrollStateChanged(recyclerView, 0, y, newState);
                        }
                    }
                }
            }
        }

        @Override
        public void onScrolled(RecyclerView recyclerView, int dx, int dy) {
            super.onScrolled(recyclerView, dx, dy);
            List<OnWXScrollListener> listeners = getInstance().getWXScrollListeners();
            if (listeners != null && listeners.size() > 0) {
                try {
                    for (OnWXScrollListener listener : listeners) {
                        if (listener != null) {
                            if (listener instanceof ICheckBindingScroller) {
                                if (((ICheckBindingScroller) listener).isNeedScroller(getRef(), null)) {
                                    listener.onScrolled(recyclerView, dx, dy);
                                }
                            } else {
                                listener.onScrolled(recyclerView, dx, dy);
                            }
                        }
                    }
                } catch (Exception e) {
                    e.printStackTrace();
                }
            }
        }
    });
    bounceRecyclerView.getViewTreeObserver().addOnGlobalLayoutListener(new ViewTreeObserver.OnGlobalLayoutListener() {

        @TargetApi(Build.VERSION_CODES.JELLY_BEAN)
        @Override
        public void onGlobalLayout() {
            BounceRecyclerView view;
            if ((view = getHostView()) == null)
                return;
            mViewOnScrollListener.onScrolled(view.getInnerView(), 0, 0);
            if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) {
                view.getViewTreeObserver().removeOnGlobalLayoutListener(this);
            } else {
                view.getViewTreeObserver().removeGlobalOnLayoutListener(this);
            }
        }
    });
    listUpdateRunnable = new Runnable() {

        @Override
        public void run() {
            /**
             * compute sticky position
             */
            if (mStickyHelper != null) {
                if (mStickyHelper.getStickyTypes().size() > 0) {
                    mStickyHelper.getStickyPositions().clear();
                    if (cellDataManager.listData != null) {
                        for (int i = 0; i < cellDataManager.listData.size(); i++) {
                            WXCell cell = getSourceTemplate(i);
                            if (cell == null) {
                                continue;
                            }
                            if (cell.isSticky()) {
                                mStickyHelper.getStickyPositions().add(i);
                            }
                        }
                    }
                }
            }
            if (getHostView() != null && getHostView().getRecyclerViewBaseAdapter() != null) {
                getHostView().getRecyclerViewBaseAdapter().notifyDataSetChanged();
            }
            if (WXEnvironment.isOpenDebugLog() && ENABLE_TRACE_LOG) {
                WXLogUtils.d(TAG, "WXTemplateList notifyDataSetChanged");
            }
        }
    };
    return bounceRecyclerView;
}
Also used : BounceRecyclerView(com.taobao.weex.ui.view.refresh.wrapper.BounceRecyclerView) ICheckBindingScroller(com.taobao.weex.common.ICheckBindingScroller) OnWXScrollListener(com.taobao.weex.common.OnWXScrollListener) 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) Point(android.graphics.Point) WXCell(com.taobao.weex.ui.component.list.WXCell) RecyclerViewBaseAdapter(com.taobao.weex.ui.view.listview.adapter.RecyclerViewBaseAdapter) WXRecyclerView(com.taobao.weex.ui.view.listview.WXRecyclerView) RecyclerView(android.support.v7.widget.RecyclerView) BounceRecyclerView(com.taobao.weex.ui.view.refresh.wrapper.BounceRecyclerView) List(java.util.List) ArrayList(java.util.ArrayList) ViewTreeObserver(android.view.ViewTreeObserver) TargetApi(android.annotation.TargetApi) WXAttr(com.taobao.weex.dom.WXAttr)

Aggregations

WXCell (com.taobao.weex.ui.component.list.WXCell)19 WXDomObject (com.taobao.weex.dom.WXDomObject)7 WXRecyclerView (com.taobao.weex.ui.view.listview.WXRecyclerView)7 JSONObject (com.alibaba.fastjson.JSONObject)6 Point (android.graphics.Point)5 View (android.view.View)5 WXCellDomObject (com.taobao.weex.dom.WXCellDomObject)5 WXRecyclerDomObject (com.taobao.weex.dom.WXRecyclerDomObject)4 WXComponent (com.taobao.weex.ui.component.WXComponent)4 BounceRecyclerView (com.taobao.weex.ui.view.refresh.wrapper.BounceRecyclerView)4 RecyclerView (android.support.v7.widget.RecyclerView)3 WXAttr (com.taobao.weex.dom.WXAttr)3 ListComponentView (com.taobao.weex.ui.component.list.ListComponentView)3 ArrayMap (android.support.v4.util.ArrayMap)2 ViewGroup (android.view.ViewGroup)2 AppearanceHelper (com.taobao.weex.ui.component.AppearanceHelper)2 WXDiv (com.taobao.weex.ui.component.WXDiv)2 ArrayList (java.util.ArrayList)2 HashMap (java.util.HashMap)2 List (java.util.List)2