http://git-wip-us.apache.org/repos/asf/incubator-weex/blob/2f8caedb/android/sdk/src/main/java/com/taobao/weex/ui/component/list/GapItemDecoration.java ---------------------------------------------------------------------- diff --git a/android/sdk/src/main/java/com/taobao/weex/ui/component/list/GapItemDecoration.java b/android/sdk/src/main/java/com/taobao/weex/ui/component/list/GapItemDecoration.java index a721a4e..1808c16 100644 --- a/android/sdk/src/main/java/com/taobao/weex/ui/component/list/GapItemDecoration.java +++ b/android/sdk/src/main/java/com/taobao/weex/ui/component/list/GapItemDecoration.java @@ -23,7 +23,6 @@ import android.support.v7.widget.RecyclerView; import android.support.v7.widget.StaggeredGridLayoutManager; import android.view.View; -import com.taobao.weex.dom.WXRecyclerDomObject; import com.taobao.weex.ui.component.WXComponent; import com.taobao.weex.utils.WXViewUtils; @@ -42,30 +41,31 @@ public class GapItemDecoration extends RecyclerView.ItemDecoration { @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; - } - } + // TODO +// 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; +// } +// } } }
http://git-wip-us.apache.org/repos/asf/incubator-weex/blob/2f8caedb/android/sdk/src/main/java/com/taobao/weex/ui/component/list/HorizontalListComponent.java ---------------------------------------------------------------------- diff --git a/android/sdk/src/main/java/com/taobao/weex/ui/component/list/HorizontalListComponent.java b/android/sdk/src/main/java/com/taobao/weex/ui/component/list/HorizontalListComponent.java index 495d4fa..aebde71 100644 --- a/android/sdk/src/main/java/com/taobao/weex/ui/component/list/HorizontalListComponent.java +++ b/android/sdk/src/main/java/com/taobao/weex/ui/component/list/HorizontalListComponent.java @@ -21,7 +21,7 @@ package com.taobao.weex.ui.component.list; import com.taobao.weex.WXSDKInstance; import com.taobao.weex.annotation.Component; import com.taobao.weex.common.Constants; -import com.taobao.weex.dom.WXDomObject; +import com.taobao.weex.ui.action.BasicComponentData; import com.taobao.weex.ui.component.WXVContainer; /** @@ -30,8 +30,8 @@ import com.taobao.weex.ui.component.WXVContainer; @Component(lazyload = false) public class HorizontalListComponent extends WXListComponent { - public HorizontalListComponent(WXSDKInstance instance, WXDomObject node, WXVContainer parent, boolean lazy) { - super(instance, node, parent, lazy); + public HorizontalListComponent(WXSDKInstance instance, WXVContainer parent, boolean lazy, BasicComponentData basicComponentData) { + super(instance, parent, lazy, basicComponentData); } @Override http://git-wip-us.apache.org/repos/asf/incubator-weex/blob/2f8caedb/android/sdk/src/main/java/com/taobao/weex/ui/component/list/SimpleListComponent.java ---------------------------------------------------------------------- diff --git a/android/sdk/src/main/java/com/taobao/weex/ui/component/list/SimpleListComponent.java b/android/sdk/src/main/java/com/taobao/weex/ui/component/list/SimpleListComponent.java index 54f7bb9..288abe0 100644 --- a/android/sdk/src/main/java/com/taobao/weex/ui/component/list/SimpleListComponent.java +++ b/android/sdk/src/main/java/com/taobao/weex/ui/component/list/SimpleListComponent.java @@ -21,7 +21,7 @@ package com.taobao.weex.ui.component.list; import android.content.Context; import com.taobao.weex.WXSDKInstance; -import com.taobao.weex.dom.WXDomObject; +import com.taobao.weex.ui.action.BasicComponentData; import com.taobao.weex.ui.component.WXVContainer; import com.taobao.weex.ui.view.listview.WXRecyclerView; @@ -32,8 +32,8 @@ import com.taobao.weex.ui.view.listview.WXRecyclerView; */ public class SimpleListComponent extends BasicListComponent<SimpleRecyclerView>{ - public SimpleListComponent(WXSDKInstance instance, WXDomObject node, WXVContainer parent) { - super(instance, node, parent); + public SimpleListComponent(WXSDKInstance instance, WXVContainer parent, BasicComponentData basicComponentData) { + super(instance, parent, basicComponentData); } @Override http://git-wip-us.apache.org/repos/asf/incubator-weex/blob/2f8caedb/android/sdk/src/main/java/com/taobao/weex/ui/component/list/StickyHeaderHelper.java ---------------------------------------------------------------------- diff --git a/android/sdk/src/main/java/com/taobao/weex/ui/component/list/StickyHeaderHelper.java b/android/sdk/src/main/java/com/taobao/weex/ui/component/list/StickyHeaderHelper.java index 5d744c6..8dc5608 100644 --- a/android/sdk/src/main/java/com/taobao/weex/ui/component/list/StickyHeaderHelper.java +++ b/android/sdk/src/main/java/com/taobao/weex/ui/component/list/StickyHeaderHelper.java @@ -103,7 +103,7 @@ public class StickyHeaderHelper { headerView.setTranslationY(translationY); } changeFrontStickyVisible(); - if (headComponent.getDomObject().getEvents().contains("sticky")) { + if (headComponent.getEvents().contains("sticky")) { headComponent.fireEvent("sticky"); } } @@ -130,14 +130,14 @@ public class StickyHeaderHelper { public void run() { mParent.removeView(headerView); if(headerView.getVisibility() != View.VISIBLE){ - headerView.setVisibility(View.VISIBLE); + headerView.setVisibility(View.VISIBLE); } component.recoverySticky(); changeFrontStickyVisible(); } })); - if (component.getDomObject().getEvents().contains("unsticky")) { + if (component.getEvents().contains("unsticky")) { component.fireEvent("unsticky"); } } @@ -167,13 +167,13 @@ public class StickyHeaderHelper { } public void clearStickyHeaders(){ - if(mHeaderViews.size() <= 0){ - return; - } - Set<String> keys = mHeaderViews.keySet(); - for(String key : keys){ - notifyStickyRemove(mHeaderComps.get(key)); - } + if(mHeaderViews.size() <= 0){ + return; + } + Set<String> keys = mHeaderViews.keySet(); + for(String key : keys){ + notifyStickyRemove(mHeaderComps.get(key)); + } } @@ -183,19 +183,19 @@ public class StickyHeaderHelper { } boolean fontVisible = false; for(int i=mParent.getChildCount()-1; i>=0; i--){ - View view = mParent.getChildAt(i); - if(fontVisible && view.getTag() instanceof StickyHeaderHelper){ - if(view.getVisibility() != View.GONE){ - view.setVisibility(View.GONE); - } - }else{ - if(view.getTag() instanceof StickyHeaderHelper){ - fontVisible = true; - if(view != null && view.getVisibility() != View.VISIBLE){ - view.setVisibility(View.VISIBLE); - } - } - } + View view = mParent.getChildAt(i); + if(fontVisible && view.getTag() instanceof StickyHeaderHelper){ + if(view.getVisibility() != View.GONE){ + view.setVisibility(View.GONE); + } + }else{ + if(view.getTag() instanceof StickyHeaderHelper){ + fontVisible = true; + if(view != null && view.getVisibility() != View.VISIBLE){ + view.setVisibility(View.VISIBLE); + } + } + } } } } http://git-wip-us.apache.org/repos/asf/incubator-weex/blob/2f8caedb/android/sdk/src/main/java/com/taobao/weex/ui/component/list/WXCell.java ---------------------------------------------------------------------- diff --git a/android/sdk/src/main/java/com/taobao/weex/ui/component/list/WXCell.java b/android/sdk/src/main/java/com/taobao/weex/ui/component/list/WXCell.java index 935f7e6..d6df19e 100644 --- a/android/sdk/src/main/java/com/taobao/weex/ui/component/list/WXCell.java +++ b/android/sdk/src/main/java/com/taobao/weex/ui/component/list/WXCell.java @@ -18,28 +18,27 @@ */ package com.taobao.weex.ui.component.list; +import static com.taobao.weex.common.Constants.Name.STICKY_OFFSET; + import android.content.Context; import android.os.Build; -import android.os.Build.VERSION_CODES; import android.support.annotation.NonNull; import android.support.annotation.RestrictTo; -import android.support.annotation.RestrictTo.Scope; import android.view.View; import android.view.ViewGroup; import android.widget.FrameLayout; import com.taobao.weex.WXSDKInstance; import com.taobao.weex.annotation.Component; -import com.taobao.weex.common.Constants.Name; +import com.taobao.weex.common.Constants; import com.taobao.weex.dom.WXAttr; -import com.taobao.weex.dom.WXDomObject; +import com.taobao.weex.ui.action.BasicComponentData; import com.taobao.weex.ui.component.WXVContainer; import com.taobao.weex.ui.flat.WidgetContainer; import com.taobao.weex.ui.view.WXFrameLayout; import com.taobao.weex.utils.WXLogUtils; import com.taobao.weex.utils.WXUtils; import com.taobao.weex.utils.WXViewUtils; - -import static com.taobao.weex.common.Constants.Name.STICKY_OFFSET; +import java.util.LinkedList; /** * Root component for components in {@link WXListComponent} @@ -54,7 +53,7 @@ public class WXCell extends WidgetContainer<WXFrameLayout> { private View mHeadView; /** used in list sticky detect **/ - private int mScrollPositon = -1; + private int mScrollPosition = -1; private boolean mFlatUIEnabled = false; @@ -62,22 +61,20 @@ public class WXCell extends WidgetContainer<WXFrameLayout> { private boolean isSourceUsed = false; - @Deprecated - public WXCell(WXSDKInstance instance, WXDomObject dom, WXVContainer parent, String instanceId, boolean isLazy) { - super(instance, dom, parent); - lazy(true); + public WXCell(WXSDKInstance instance, WXVContainer parent, String instanceId, boolean isLazy, BasicComponentData basicComponentData) { + super(instance, parent, basicComponentData); } - public WXCell(WXSDKInstance instance, WXDomObject dom, WXVContainer parent, boolean isLazy) { - super(instance, dom, parent); + public WXCell(WXSDKInstance instance, WXVContainer parent, boolean isLazy, BasicComponentData basicComponentData) { + super(instance, parent, basicComponentData); lazy(true); - if(Build.VERSION.SDK_INT< VERSION_CODES.LOLLIPOP) { + if(Build.VERSION.SDK_INT< Build.VERSION_CODES.LOLLIPOP) { try { //TODO a WTF is necessary if anyone try to change the flat flag during update attrs. - WXAttr attr = getDomObject().getAttrs(); - if (attr.containsKey(Name.FLAT)) { - mFlatUIEnabled = WXUtils.getBoolean(attr.get(Name.FLAT), false); + WXAttr attr = getAttrs(); + if (attr.containsKey(Constants.Name.FLAT)) { + mFlatUIEnabled = WXUtils.getBoolean(attr.get(Constants.Name.FLAT), false); } } catch (NullPointerException e) { WXLogUtils.e("Cell", WXLogUtils.getStackTrace(e)); @@ -90,10 +87,8 @@ public class WXCell extends WidgetContainer<WXFrameLayout> { return super.isLazy() && !isFixed(); } - - @Override - @RestrictTo(Scope.LIBRARY) + @RestrictTo(RestrictTo.Scope.LIBRARY) public boolean isFlatUIEnabled() { return mFlatUIEnabled; } @@ -130,12 +125,12 @@ public class WXCell extends WidgetContainer<WXFrameLayout> { mLastLocationY = l; } - public void setScrollPositon(int pos){ - mScrollPositon = pos; + void setScrollPositon(int pos){ + mScrollPosition = pos; } public int getScrollPositon() { - return mScrollPositon; + return mScrollPosition; } @Override @@ -155,8 +150,8 @@ public class WXCell extends WidgetContainer<WXFrameLayout> { getHostView().removeView(mHeadView); mRealView = (ViewGroup) mHeadView; mTempStickyView = new FrameLayout(getContext()); - FrameLayout.LayoutParams lp = new FrameLayout.LayoutParams((int) getDomObject().getLayoutWidth(), - (int) getDomObject().getLayoutHeight()); + FrameLayout.LayoutParams lp = new FrameLayout.LayoutParams((int) getLayoutWidth(), + (int) getLayoutHeight()); getHostView().addView(mTempStickyView, lp); mHeadView.setTranslationX(headerViewOffsetX); mHeadView.setTranslationY(headerViewOffsetY); @@ -177,10 +172,8 @@ public class WXCell extends WidgetContainer<WXFrameLayout> { if(mHeadView.getParent() != null){ ((ViewGroup)mHeadView.getParent()).removeView(mHeadView); } - if(getHostView() != null) { - getHostView().removeView(mTempStickyView); - getHostView().addView(mHeadView); - } + getHostView().removeView(mTempStickyView); + getHostView().addView(mHeadView); mHeadView.setTranslationX(0); mHeadView.setTranslationY(0); } @@ -188,9 +181,12 @@ public class WXCell extends WidgetContainer<WXFrameLayout> { @Override protected void mountFlatGUI() { - if(getHostView()!=null) { - getHostView().mountFlatGUI(widgets); - } + if(getHostView()!=null) { + if(widgets == null){ + widgets = new LinkedList<>(); + } + getHostView().mountFlatGUI(widgets); + } } @Override @@ -206,15 +202,11 @@ public class WXCell extends WidgetContainer<WXFrameLayout> { } public int getStickyOffset(){ - if(getDomObject() == null){ - return 0; - } - WXDomObject domObject = (WXDomObject) getDomObject(); - if(domObject.getAttrs().get(STICKY_OFFSET) == null){ + if(getAttrs().get(STICKY_OFFSET) == null){ return 0; } - float offset = WXUtils.getFloat(domObject.getAttrs().get(STICKY_OFFSET)); - return (int)(WXViewUtils.getRealPxByWidth(offset,domObject.getViewPortWidth())); + float offset = WXUtils.getFloat(getAttrs().get(STICKY_OFFSET)); + return (int)(WXViewUtils.getRealPxByWidth(offset, getViewPortWidth())); } public Object getRenderData() { @@ -232,5 +224,4 @@ public class WXCell extends WidgetContainer<WXFrameLayout> { public void setSourceUsed(boolean sourceUsed) { isSourceUsed = sourceUsed; } - } http://git-wip-us.apache.org/repos/asf/incubator-weex/blob/2f8caedb/android/sdk/src/main/java/com/taobao/weex/ui/component/list/WXListComponent.java ---------------------------------------------------------------------- diff --git a/android/sdk/src/main/java/com/taobao/weex/ui/component/list/WXListComponent.java b/android/sdk/src/main/java/com/taobao/weex/ui/component/list/WXListComponent.java index fb5597f..3519db2 100644 --- a/android/sdk/src/main/java/com/taobao/weex/ui/component/list/WXListComponent.java +++ b/android/sdk/src/main/java/com/taobao/weex/ui/component/list/WXListComponent.java @@ -19,15 +19,14 @@ package com.taobao.weex.ui.component.list; import android.content.Context; -import android.util.Pair; +import android.util.Log; import com.taobao.weex.WXSDKInstance; import com.taobao.weex.annotation.Component; import com.taobao.weex.common.Constants; import com.taobao.weex.common.WXThread; -import com.taobao.weex.dom.WXDomObject; -import com.taobao.weex.dom.WXRecyclerDomObject; -import com.taobao.weex.dom.flex.Spacing; +import com.taobao.weex.dom.CSSShorthand; +import com.taobao.weex.ui.action.BasicComponentData; import com.taobao.weex.ui.component.WXBaseRefresh; import com.taobao.weex.ui.component.WXBasicComponentType; import com.taobao.weex.ui.component.WXComponent; @@ -38,6 +37,7 @@ import com.taobao.weex.ui.component.WXVContainer; import com.taobao.weex.ui.view.listview.WXRecyclerView; import com.taobao.weex.ui.view.listview.adapter.ListBaseViewHolder; import com.taobao.weex.ui.view.refresh.wrapper.BounceRecyclerView; +import com.taobao.weex.utils.WXLogUtils; import com.taobao.weex.utils.WXUtils; import java.util.Map; @@ -53,122 +53,128 @@ import java.util.Map; public class WXListComponent extends BasicListComponent<BounceRecyclerView> { private String TAG = "WXListComponent"; - private WXRecyclerDomObject mRecyclerDom; + // private WXRecyclerDomObject mDomObject; private float mPaddingLeft; private float mPaddingRight; @Deprecated - public WXListComponent(WXSDKInstance instance, WXDomObject dom, WXVContainer parent, String instanceId, boolean isLazy) { - this(instance, dom, parent, isLazy); + public WXListComponent(WXSDKInstance instance, WXVContainer parent, String instanceId, boolean isLazy, BasicComponentData basicComponentData) { + this(instance, parent, isLazy, basicComponentData); } - public WXListComponent(WXSDKInstance instance, WXDomObject node, WXVContainer parent, boolean lazy) { - super(instance, node, parent); - if (node != null && node instanceof WXRecyclerDomObject) { - mRecyclerDom = (WXRecyclerDomObject) node; - mRecyclerDom.preCalculateCellWidth(); - - if(WXBasicComponentType.WATERFALL.equals(node.getType())){ - mLayoutType = WXRecyclerView.TYPE_STAGGERED_GRID_LAYOUT; - }else{ - mLayoutType = mRecyclerDom.getLayoutType(); - } - updateRecyclerAttr(); - - } + public WXListComponent(WXSDKInstance instance, WXVContainer parent, boolean lazy, BasicComponentData basicComponentData) { + super(instance, parent, basicComponentData); } @Override protected BounceRecyclerView generateListView(Context context, int orientation) { - BounceRecyclerView bounceRecyclerView = new BounceRecyclerView(context,mLayoutType,mColumnCount,mColumnGap,orientation); - if(bounceRecyclerView.getSwipeLayout() != null){ - if(WXUtils.getBoolean(getDomObject().getAttrs().get(Constants.Name.NEST_SCROLLING_ENABLED), false)) { - bounceRecyclerView.getSwipeLayout().setNestedScrollingEnabled(true); + BounceRecyclerView bounceRecyclerView = new BounceRecyclerView(context, mLayoutType, mColumnCount, mColumnGap, orientation); + if (bounceRecyclerView.getSwipeLayout() != null) { + if (WXUtils.getBoolean(getAttrs().get(Constants.Name.NEST_SCROLLING_ENABLED), false)) { + bounceRecyclerView.getSwipeLayout().setNestedScrollingEnabled(true); } } - if(mRecyclerDom != null && mRecyclerDom.getSpanOffsets() != null){ - bounceRecyclerView.getInnerView().addItemDecoration(new GapItemDecoration(this)); - } - return bounceRecyclerView; + // TODO + // if(mRecyclerDom != null && mRecyclerDom.getSpanOffsets() != null){ + // bounceRecyclerView.getInnerView().addItemDecoration(new GapItemDecoration(this)); + // } + return bounceRecyclerView; } @Override - public void addChild(final WXComponent child, int index) { + public void addChild(WXComponent child, int index) { super.addChild(child, index); if (child == null || index < -1) { return; } + setRefreshOrLoading(child); + // Synchronize DomObject's attr to Component and Native View + if(getHostView() != null && hasColumnPros()) { + updateRecyclerAttr(); + getHostView().getInnerView().initView(getContext(), mLayoutType,mColumnCount,mColumnGap,getOrientation()); + } + } - if (child instanceof WXRefresh && getHostView() != null) { - getHostView().setOnRefreshListener((WXRefresh) child); - getHostView().postDelayed(WXThread.secure(new Runnable() { + private boolean hasColumnPros() { + return mColumnWidth != WXUtils.parseFloat(getAttrs().get(Constants.Name.COLUMN_WIDTH)) || + mColumnCount != WXUtils.parseInt(getAttrs().get(Constants.Name.COLUMN_COUNT)) || + mColumnGap != WXUtils.parseFloat(getAttrs().get(Constants.Name.COLUMN_GAP)); + } + + /** + * Setting refresh view and loading view + * + * @param child the refresh_view or loading_view + */ + private boolean setRefreshOrLoading(final WXComponent child) { + + if (getHostView() == null) { + WXLogUtils.e(TAG, "setRefreshOrLoading: HostView == null !!!!!! check list attr has append =tree"); + return true; + } + if (child instanceof WXRefresh) { + getHostView().setOnRefreshListener((WXRefresh) child); + getHostView().postDelayed(WXThread.secure(new Runnable() { @Override public void run() { getHostView().setHeaderView(child); } }), 100); + return true; } - if (child instanceof WXLoading && getHostView() != null) { - getHostView().setOnLoadingListener((WXLoading) child); - getHostView().postDelayed(WXThread.secure(new Runnable() { + if (child instanceof WXLoading) { + getHostView().setOnLoadingListener((WXLoading) child); + getHostView().postDelayed(WXThread.secure(new Runnable() { @Override public void run() { getHostView().setFooterView(child); } }), 100); + return true; } - - // Synchronize DomObject's attr to Component and Native View - if(mRecyclerDom != null && getHostView() != null && (mColumnWidth != mRecyclerDom.getColumnWidth() || - mColumnCount != mRecyclerDom.getColumnCount() || - mColumnGap != mRecyclerDom.getColumnGap())) { - updateRecyclerAttr(); - getHostView().getInnerView().initView(getContext(), mLayoutType,mColumnCount,mColumnGap,getOrientation()); - } - } - - - - private void updateRecyclerAttr(){ - if(mRecyclerDom != null) { - mColumnCount = mRecyclerDom.getColumnCount(); - mColumnGap = mRecyclerDom.getColumnGap(); - mColumnWidth = mRecyclerDom.getColumnWidth(); - mPaddingLeft = mRecyclerDom.getPadding().get(Spacing.LEFT); - mPaddingRight = mRecyclerDom.getPadding().get(Spacing.RIGHT); - mLeftGap = mRecyclerDom.getLeftGap(); - mRightGap = mRecyclerDom.getRightGap(); - mRecyclerDom.preCalculateCellWidth(); - } + return false; } - @WXComponentProp(name = Constants.Name.LEFT_GAP) - public void setLeftGap(float leftGap) { - if(mRecyclerDom != null && mRecyclerDom.getLeftGap() != mLeftGap){ - markComponentUsable(); - mRecyclerDom.preCalculateCellWidth(); - updateRecyclerAttr(); - WXRecyclerView wxRecyclerView = getHostView().getInnerView(); - wxRecyclerView.initView(getContext(), mLayoutType,mColumnCount,mColumnGap,getOrientation()); - } + private void updateRecyclerAttr() { + mColumnCount = WXUtils.parseInt(getAttrs().get(Constants.Name.COLUMN_COUNT)); + mColumnGap = WXUtils.parseFloat(getAttrs().get(Constants.Name.COLUMN_GAP)); + mColumnWidth = WXUtils.parseFloat(getAttrs().get(Constants.Name.COLUMN_WIDTH)); + mPaddingLeft = WXUtils.parseFloat(getAttrs().get(Constants.Name.PADDING_LEFT)); + mPaddingRight = WXUtils.parseFloat(getAttrs().get(Constants.Name.PADDING_RIGHT)); + // TODO + // mLeftGap = mRecyclerDom.getLeftGap(); + // mRightGap = mRecyclerDom.getRightGap(); + // mRecyclerDom.preCalculateCellWidth(); } - @WXComponentProp(name = Constants.Name.RIGHT_GAP) - public void setRightGap(float rightGap) { - if(mRecyclerDom != null && mRecyclerDom.getRightGap() != mRightGap){ - markComponentUsable(); - mRecyclerDom.preCalculateCellWidth(); - updateRecyclerAttr(); - WXRecyclerView wxRecyclerView = getHostView().getInnerView(); - wxRecyclerView.initView(getContext(), mLayoutType,mColumnCount,mColumnGap,getOrientation()); - } - } + // TODO +// @WXComponentProp(name = Constants.Name.LEFT_GAP) + // public void setLeftGap(float leftGap) { + // if(mRecyclerDom != null && mRecyclerDom.getLeftGap() != mLeftGap){ + // markComponentUsable(); + // mRecyclerDom.preCalculateCellWidth(); + // updateRecyclerAttr(); + // WXRecyclerView wxRecyclerView = getHostView().getInnerView(); + // wxRecyclerView.initView(getContext(), mLayoutType,mColumnCount,mColumnGap,getOrientation()); + // } + // } + // + // @WXComponentProp(name = Constants.Name.RIGHT_GAP) + // public void setRightGap(float rightGap) { + // if(mRecyclerDom != null && mRecyclerDom.getRightGap() != mRightGap){ + // markComponentUsable(); + // mRecyclerDom.preCalculateCellWidth(); + // updateRecyclerAttr(); + // WXRecyclerView wxRecyclerView = getHostView().getInnerView(); + // wxRecyclerView.initView(getContext(), mLayoutType,mColumnCount,mColumnGap,getOrientation()); + // } + // } @WXComponentProp(name = Constants.Name.COLUMN_WIDTH) - public void setColumnWidth(int columnCount) { - if(mRecyclerDom != null && mRecyclerDom.getColumnWidth() != mColumnWidth){ + public void setColumnWidth(int columnWidth) { + if(columnWidth != mColumnWidth){ markComponentUsable(); updateRecyclerAttr(); WXRecyclerView wxRecyclerView = getHostView().getInnerView(); @@ -178,7 +184,7 @@ public class WXListComponent extends BasicListComponent<BounceRecyclerView> { @WXComponentProp(name = Constants.Name.COLUMN_COUNT) public void setColumnCount(int columnCount){ - if(mRecyclerDom != null && mRecyclerDom.getColumnCount() != mColumnCount){ + if(columnCount != mColumnCount){ markComponentUsable(); updateRecyclerAttr(); WXRecyclerView wxRecyclerView = getHostView().getInnerView(); @@ -188,7 +194,7 @@ public class WXListComponent extends BasicListComponent<BounceRecyclerView> { @WXComponentProp(name = Constants.Name.COLUMN_GAP) public void setColumnGap(float columnGap) throws InterruptedException { - if(mRecyclerDom != null && mRecyclerDom.getColumnGap() != mColumnGap) { + if(columnGap != mColumnGap) { markComponentUsable(); updateRecyclerAttr(); WXRecyclerView wxRecyclerView = getHostView().getInnerView(); @@ -205,58 +211,66 @@ public class WXListComponent extends BasicListComponent<BounceRecyclerView> { @Override public void updateProperties(Map<String, Object> props) { super.updateProperties(props); + if (isRecycler(this)) { + if(WXBasicComponentType.WATERFALL.equals(getComponentType())){ + mLayoutType = WXRecyclerView.TYPE_STAGGERED_GRID_LAYOUT; + }else{ + mLayoutType = getAttrs().getLayoutType(); + } + } + if(props.containsKey(Constants.Name.PADDING) ||props.containsKey(Constants.Name.PADDING_LEFT) || props.containsKey(Constants.Name.PADDING_RIGHT)){ - - if(mRecyclerDom != null && (mPaddingLeft != mRecyclerDom.getPadding().get(Spacing.LEFT) - || mPaddingRight != mRecyclerDom.getPadding().get(Spacing.RIGHT))) { - + if(mPaddingLeft != WXUtils.parseFloat(props.get(Constants.Name.PADDING_LEFT)) || mPaddingRight != WXUtils.parseFloat(props.get(Constants.Name.PADDING_RIGHT))) { markComponentUsable(); updateRecyclerAttr(); WXRecyclerView wxRecyclerView = getHostView().getInnerView(); wxRecyclerView.initView(getContext(), mLayoutType, mColumnCount, mColumnGap, getOrientation()); } } - } @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); + int indexToCreate = index; + if (indexToCreate < 0) { + indexToCreate = childCount() - 1; + if (indexToCreate < 0) { + return; } } - } - - public WXRecyclerDomObject getRecyclerDom() { - return mRecyclerDom; + 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); + } } public void remove(WXComponent child, boolean destroy) { super.remove(child, destroy); + removeFooterOrHeader(child); + } + + private void removeFooterOrHeader(WXComponent child) { if (child instanceof WXLoading) { getHostView().removeFooterView(child); } else if (child instanceof WXRefresh) { @@ -264,5 +278,9 @@ public class WXListComponent extends BasicListComponent<BounceRecyclerView> { } } - + private boolean isRecycler(WXComponent component) { + return WXBasicComponentType.WATERFALL.equals(component.getComponentType()) + || WXBasicComponentType.RECYCLE_LIST.equals(component.getComponentType()) + || WXBasicComponentType.RECYCLER.equals(component.getComponentType()); + } } http://git-wip-us.apache.org/repos/asf/incubator-weex/blob/2f8caedb/android/sdk/src/main/java/com/taobao/weex/ui/component/list/template/AsyncCellLoadTask.java ---------------------------------------------------------------------- diff --git a/android/sdk/src/main/java/com/taobao/weex/ui/component/list/template/AsyncCellLoadTask.java b/android/sdk/src/main/java/com/taobao/weex/ui/component/list/template/AsyncCellLoadTask.java index eb864bf..0dae3c8 100644 --- a/android/sdk/src/main/java/com/taobao/weex/ui/component/list/template/AsyncCellLoadTask.java +++ b/android/sdk/src/main/java/com/taobao/weex/ui/component/list/template/AsyncCellLoadTask.java @@ -98,7 +98,7 @@ class AsyncCellLoadTask extends AsyncTask<Void,Void, Void> { ConcurrentLinkedQueue<WXCell> queue = cellCache.cells; Iterator<WXCell> iterator = queue.iterator(); while (iterator.hasNext()){ - WXCell component = iterator.next(); + WXCell component = iterator.next(); if(component.isLazy()){ templateList.doCreateCellViewBindData(component, template, true); return iterator.hasNext(); http://git-wip-us.apache.org/repos/asf/incubator-weex/blob/2f8caedb/android/sdk/src/main/java/com/taobao/weex/ui/component/list/template/CellDataManager.java ---------------------------------------------------------------------- diff --git a/android/sdk/src/main/java/com/taobao/weex/ui/component/list/template/CellDataManager.java b/android/sdk/src/main/java/com/taobao/weex/ui/component/list/template/CellDataManager.java index 3982117..5b75346 100644 --- a/android/sdk/src/main/java/com/taobao/weex/ui/component/list/template/CellDataManager.java +++ b/android/sdk/src/main/java/com/taobao/weex/ui/component/list/template/CellDataManager.java @@ -23,7 +23,6 @@ import android.support.v4.util.ArrayMap; import android.text.TextUtils; import com.alibaba.fastjson.JSONArray; -import com.alibaba.fastjson.JSONObject; import com.taobao.weex.WXEnvironment; import com.taobao.weex.bridge.WXBridgeManager; import com.taobao.weex.utils.WXUtils; @@ -141,7 +140,7 @@ public class CellDataManager { public void setListData(JSONArray listData) { if(this.listData != listData) { if(this.listData != null){ - if(WXUtils.getBoolean(templateList.getDomObject().getAttrs().get("exitDetach"), true)){ + if(WXUtils.getBoolean(templateList.getAttrs().get("exitDetach"), true)){ for(int i=0; i<this.listData.size(); i++){ cleanRenderState(renderStates.remove(i)); } http://git-wip-us.apache.org/repos/asf/incubator-weex/blob/2f8caedb/android/sdk/src/main/java/com/taobao/weex/ui/component/list/template/TemplateCache.java ---------------------------------------------------------------------- diff --git a/android/sdk/src/main/java/com/taobao/weex/ui/component/list/template/TemplateCache.java b/android/sdk/src/main/java/com/taobao/weex/ui/component/list/template/TemplateCache.java index eab80bc..4ae98c3 100644 --- a/android/sdk/src/main/java/com/taobao/weex/ui/component/list/template/TemplateCache.java +++ b/android/sdk/src/main/java/com/taobao/weex/ui/component/list/template/TemplateCache.java @@ -17,7 +17,9 @@ * under the License. */ package com.taobao.weex.ui.component.list.template; + import com.taobao.weex.ui.component.list.WXCell; + import java.util.concurrent.ConcurrentLinkedQueue; /** http://git-wip-us.apache.org/repos/asf/incubator-weex/blob/2f8caedb/android/sdk/src/main/java/com/taobao/weex/ui/component/list/template/TemplateStickyHelper.java ---------------------------------------------------------------------- diff --git a/android/sdk/src/main/java/com/taobao/weex/ui/component/list/template/TemplateStickyHelper.java b/android/sdk/src/main/java/com/taobao/weex/ui/component/list/template/TemplateStickyHelper.java index 45c983b..ffc6b07 100644 --- a/android/sdk/src/main/java/com/taobao/weex/ui/component/list/template/TemplateStickyHelper.java +++ b/android/sdk/src/main/java/com/taobao/weex/ui/component/list/template/TemplateStickyHelper.java @@ -28,6 +28,7 @@ import android.widget.FrameLayout; import com.taobao.weex.common.Constants; import com.taobao.weex.ui.view.refresh.wrapper.BounceRecyclerView; + import java.util.ArrayList; import java.util.List; @@ -98,8 +99,7 @@ public class TemplateStickyHelper { bounceRecyclerView.removeView(stickyFakeViewHolder.itemView); stickyFakeViewHolder.itemView.setTranslationY(0); if(stickyFakeViewHolder.getComponent() != null - && stickyFakeViewHolder.getComponent().getDomObject() != null - && stickyFakeViewHolder.getComponent().getDomObject().getEvents().contains(Constants.Event.UNSTICKY)){ + && stickyFakeViewHolder.getComponent().getEvents().contains(Constants.Event.UNSTICKY)){ stickyFakeViewHolder.getComponent().fireEvent(Constants.Event.UNSTICKY); } } @@ -124,7 +124,7 @@ public class TemplateStickyHelper { //onCreate holder for match position if not exist View stickyFakeView = bounceRecyclerView.getChildAt(bounceRecyclerView.getChildCount() - 1); - if(!(stickyFakeView.getTag() instanceof TemplateViewHolder) + if(!(stickyFakeView.getTag() instanceof TemplateViewHolder) || ((TemplateViewHolder) stickyFakeView.getTag()).getHolderPosition() != matchStickyPosition){ //remove previous sticky header @@ -134,8 +134,7 @@ public class TemplateStickyHelper { bounceRecyclerView.removeView(stickyFakeViewHolder.itemView); stickyFakeViewHolder.itemView.setTranslationY(0); if(stickyFakeViewHolder.getComponent() != null - && stickyFakeViewHolder.getComponent().getDomObject() != null - && stickyFakeViewHolder.getComponent().getDomObject().getEvents().contains(Constants.Event.UNSTICKY)){ + && stickyFakeViewHolder.getComponent().getEvents().contains(Constants.Event.UNSTICKY)){ stickyFakeViewHolder.getComponent().fireEvent(Constants.Event.UNSTICKY); } } @@ -157,11 +156,10 @@ public class TemplateStickyHelper { parent.removeView(fakeStickyHolder.itemView); } bounceRecyclerView.addView(fakeStickyHolder.itemView, params); - fakeStickyHolder.getComponent().setLayout(fakeStickyHolder.getComponent().getDomObject()); + fakeStickyHolder.getComponent().setLayout(fakeStickyHolder.getComponent()); stickyFakeView = fakeStickyHolder.itemView; if(fakeStickyHolder.getComponent() != null - && fakeStickyHolder.getComponent().getDomObject() != null - && fakeStickyHolder.getComponent().getDomObject().getEvents().contains(Constants.Event.STICKY)){ + && fakeStickyHolder.getComponent().getEvents().contains(Constants.Event.STICKY)){ fakeStickyHolder.getComponent().fireEvent(Constants.Event.STICKY); } } http://git-wip-us.apache.org/repos/asf/incubator-weex/blob/2f8caedb/android/sdk/src/main/java/com/taobao/weex/ui/component/list/template/TemplateViewHolder.java ---------------------------------------------------------------------- diff --git a/android/sdk/src/main/java/com/taobao/weex/ui/component/list/template/TemplateViewHolder.java b/android/sdk/src/main/java/com/taobao/weex/ui/component/list/template/TemplateViewHolder.java index d0b5dbf..ac69c51 100644 --- a/android/sdk/src/main/java/com/taobao/weex/ui/component/list/template/TemplateViewHolder.java +++ b/android/sdk/src/main/java/com/taobao/weex/ui/component/list/template/TemplateViewHolder.java @@ -19,17 +19,9 @@ package com.taobao.weex.ui.component.list.template; import android.os.AsyncTask; import android.view.View; - -import com.taobao.weex.annotation.Component; -import com.taobao.weex.dom.flex.CSSLayoutContext; -import com.taobao.weex.ui.component.WXComponent; -import com.taobao.weex.ui.component.WXVContainer; import com.taobao.weex.ui.component.list.WXCell; import com.taobao.weex.ui.view.listview.adapter.ListBaseViewHolder; -import java.util.ArrayList; -import java.util.List; - /** * Created by furture on 2017/8/17. */ @@ -41,7 +33,8 @@ public class TemplateViewHolder extends ListBaseViewHolder { * */ private WXCell template; - private CSSLayoutContext layoutContext; + // TODO +// private CSSLayoutContext layoutContext; private int holderPosition = -1; @@ -62,16 +55,17 @@ public class TemplateViewHolder extends ListBaseViewHolder { super(view, viewType); } - public CSSLayoutContext getLayoutContext() { - if(layoutContext == null){ - layoutContext = new CSSLayoutContext(); - } - return layoutContext; - } - - public void setLayoutContext(CSSLayoutContext layoutContext){ - this.layoutContext = layoutContext; - } + // TODO +// public CSSLayoutContext getLayoutContext() { +// if(layoutContext == null){ +// layoutContext = new CSSLayoutContext(); +// } +// return layoutContext; +// } +// +// public void setLayoutContext(CSSLayoutContext layoutContext){ +// this.layoutContext = layoutContext; +// } public int getHolderPosition() { http://git-wip-us.apache.org/repos/asf/incubator-weex/blob/2f8caedb/android/sdk/src/main/java/com/taobao/weex/ui/component/list/template/WXRecyclerTemplateList.java ---------------------------------------------------------------------- diff --git a/android/sdk/src/main/java/com/taobao/weex/ui/component/list/template/WXRecyclerTemplateList.java b/android/sdk/src/main/java/com/taobao/weex/ui/component/list/template/WXRecyclerTemplateList.java index 879b7b4..83a4246 100644 --- a/android/sdk/src/main/java/com/taobao/weex/ui/component/list/template/WXRecyclerTemplateList.java +++ b/android/sdk/src/main/java/com/taobao/weex/ui/component/list/template/WXRecyclerTemplateList.java @@ -49,14 +49,11 @@ import com.taobao.weex.common.Constants; import com.taobao.weex.common.ICheckBindingScroller; import com.taobao.weex.common.OnWXScrollListener; import com.taobao.weex.common.WXThread; +import com.taobao.weex.dom.CSSShorthand; import com.taobao.weex.dom.WXAttr; -import com.taobao.weex.dom.WXCellDomObject; -import com.taobao.weex.dom.WXDomObject; import com.taobao.weex.dom.WXEvent; -import com.taobao.weex.dom.WXRecyclerDomObject; -import com.taobao.weex.dom.flex.CSSLayoutContext; -import com.taobao.weex.dom.flex.Spacing; import com.taobao.weex.el.parse.ArrayStack; +import com.taobao.weex.ui.action.BasicComponentData; import com.taobao.weex.ui.component.AppearanceHelper; import com.taobao.weex.ui.component.ComponentUtils; import com.taobao.weex.ui.component.Scrollable; @@ -111,8 +108,8 @@ public class WXRecyclerTemplateList extends WXVContainer<BounceRecyclerView> imp private static final String NAME_ITEM_VIEW_CACHE_SIZE = "itemViewCacheSize"; private static final String NAME_TEMPLATE_CACHE_SIZE = "templateCacheSize"; - - private WXRecyclerDomObject mDomObject; + // TODO +// private WXRecyclerDomObject mDomObject; protected int mLayoutType = WXRecyclerView.TYPE_LINEAR_LAYOUT; protected int mColumnCount = 1; protected float mColumnGap = 0; @@ -189,30 +186,37 @@ public class WXRecyclerTemplateList extends WXVContainer<BounceRecyclerView> imp private CellRenderContext cellRenderContext = new CellRenderContext(); - public WXRecyclerTemplateList(WXSDKInstance instance, WXDomObject node, WXVContainer parent) { - super(instance, node, parent); - initRecyclerTemplateList(instance, node, parent); + public WXRecyclerTemplateList(WXSDKInstance instance, WXVContainer parent, BasicComponentData basicComponentData) { + super(instance, parent, basicComponentData); + initRecyclerTemplateList(instance, + // TODO +// , node + parent); } - private void initRecyclerTemplateList(WXSDKInstance instance, WXDomObject node, WXVContainer parent){ - if (node != null && node instanceof WXRecyclerDomObject) { - mDomObject = (WXRecyclerDomObject) node; - mDomObject.preCalculateCellWidth(); - mLayoutType = mDomObject.getLayoutType(); - updateRecyclerAttr(); - } + private void initRecyclerTemplateList(WXSDKInstance instance, + // TODO +// WXDomObject node, + WXVContainer parent){ + // TODO +// mDomObject = (WXRecyclerDomObject) node; +// mDomObject.preCalculateCellWidth(); +// mLayoutType = mDomObject.getLayoutType(); + updateRecyclerAttr(); + mTemplateViewTypes = new ArrayMap<>(); mTemplateViewTypes.put(EMPTY_HOLDER_TEMPLATE_KEY, 0); //empty view, when template was not sended 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); + // TODO +// orientation = mDomObject.getOrientation(); + listDataTemplateKey = WXUtils.getString(getAttrs().get(Constants.Name.Recycler.LIST_DATA_TEMPLATE_SWITCH_KEY), Constants.Name.Recycler.SLOT_TEMPLATE_CASE); + listDataItemKey = WXUtils.getString(getAttrs().get(Constants.Name.Recycler.LIST_DATA_ITEM), listDataItemKey); + listDataIndexKey = WXUtils.getString(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(getAttrs().get(Constants.Name.Recycler.LIST_DATA) instanceof JSONArray) { + JSONArray array = (JSONArray) getAttrs().get(Constants.Name.Recycler.LIST_DATA); if(array.size() > 0) { cellDataManager.listData = array; } @@ -222,34 +226,35 @@ public class WXRecyclerTemplateList extends WXVContainer<BounceRecyclerView> imp * 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); - } + // TODO +// 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); +// } } @Override protected BounceRecyclerView initComponentHostView(@NonNull Context context) { final BounceRecyclerView bounceRecyclerView = new BounceRecyclerView(context,mLayoutType,mColumnCount,mColumnGap, getOrientation()); - WXAttr attrs = getDomObject().getAttrs(); + WXAttr attrs = getAttrs(); String transforms = (String) attrs.get(Constants.Name.TRANSFORM); if (transforms != null) { bounceRecyclerView.getInnerView().addItemDecoration(RecyclerTransform.parseTransforms(getOrientation(), transforms)); @@ -263,7 +268,7 @@ public class WXRecyclerTemplateList extends WXVContainer<BounceRecyclerView> imp 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); + itemViewCacheSize = WXUtils.getNumberInt(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); @@ -275,7 +280,7 @@ public class WXRecyclerTemplateList extends WXVContainer<BounceRecyclerView> imp bounceRecyclerView.getInnerView().setItemViewCacheSize(itemViewCacheSize); } if(bounceRecyclerView.getSwipeLayout() != null){ - if(WXUtils.getBoolean(getDomObject().getAttrs().get("nestedScrollingEnabled"), false)) { + if(WXUtils.getBoolean(getAttrs().get("nestedScrollingEnabled"), false)) { bounceRecyclerView.getSwipeLayout().setNestedScrollingEnabled(true); } } @@ -404,7 +409,7 @@ public class WXRecyclerTemplateList extends WXVContainer<BounceRecyclerView> imp @Override public void bindStickStyle(WXComponent component) { - WXComponent template = findParentType(component, WXCell.class); + WXComponent template = findParentType(component, WXCell.class); if(template == null){ return; } @@ -419,7 +424,7 @@ public class WXRecyclerTemplateList extends WXVContainer<BounceRecyclerView> imp @Override public void unbindStickStyle(WXComponent component) { - WXComponent template = findParentType(component, WXCell.class); + WXComponent template = findParentType(component, WXCell.class); if(template == null || cellDataManager.listData == null || mStickyHelper == null){ @@ -431,8 +436,9 @@ public class WXRecyclerTemplateList extends WXVContainer<BounceRecyclerView> imp } } - private @Nullable WXCell findCell(WXComponent component) { - if(component instanceof WXCell){ + private @Nullable + WXCell findCell(WXComponent component) { + if(component instanceof WXCell){ return (WXCell) component; } WXComponent parent; @@ -606,44 +612,45 @@ public class WXRecyclerTemplateList extends WXVContainer<BounceRecyclerView> imp /** * dom object in component is not tree, build tree * */ - if(!(child instanceof WXCell)) { + if(!(child instanceof WXCell)) { super.addChild(child, index); } - if(child instanceof WXBaseRefresh){ + 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); + if(child.getAttrs() != null){ + Object templateId = child.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(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); + child.getAttrs().put(Constants.Name.Recycler.SLOT_TEMPLATE_CASE, key); } } }else{ if(defaultTemplateCell == null - || child.getDomObject().getAttrs().containsKey(Constants.Name.Recycler.SLOT_TEMPLATE_DEFAULT)){ + || child.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); + child.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()); - } + // TODO +// 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){ @@ -757,29 +764,30 @@ public class WXRecyclerTemplateList extends WXVContainer<BounceRecyclerView> imp private void updateRecyclerAttr(){ - mColumnCount = mDomObject.getColumnCount(); - mColumnGap = mDomObject.getColumnGap(); - mColumnWidth = mDomObject.getColumnWidth(); - mPaddingLeft =mDomObject.getPadding().get(Spacing.LEFT); - mPaddingRight =mDomObject.getPadding().get(Spacing.RIGHT); + mColumnCount = getAttrs().getColumnCount(); + mColumnGap = getAttrs().getColumnGap(); + mColumnWidth = getAttrs().getColumnWidth(); + mPaddingLeft = getPadding().get(CSSShorthand.EDGE.LEFT); + mPaddingRight = getPadding().get(CSSShorthand.EDGE.RIGHT); } @WXComponentProp(name = Constants.Name.SCROLL_DIRECTION) public void setScrollDirection(String direction){ - if(orientation != mDomObject.getOrientation()) { - orientation = mDomObject.getOrientation(); - updateRecyclerAttr(); - WXRecyclerView wxRecyclerView = getHostView().getInnerView(); - wxRecyclerView.initView(getContext(), mLayoutType,mColumnCount,mColumnGap, getOrientation()); - - } + // TODO +// if(orientation != mDomObject.getOrientation()) { +// orientation = mDomObject.getOrientation(); +// updateRecyclerAttr(); +// WXRecyclerView wxRecyclerView = getHostView().getInnerView(); +// wxRecyclerView.initView(getContext(), mLayoutType,mColumnCount,mColumnGap, getOrientation()); +// +// } } @WXComponentProp(name = Constants.Name.COLUMN_WIDTH) public void setColumnWidth(int columnCount) { - if(mDomObject.getColumnWidth() != mColumnWidth){ + if(getAttrs().getColumnWidth() != mColumnWidth){ updateRecyclerAttr(); WXRecyclerView wxRecyclerView = getHostView().getInnerView(); wxRecyclerView.initView(getContext(), mLayoutType,mColumnCount,mColumnGap, getOrientation()); @@ -800,7 +808,7 @@ public class WXRecyclerTemplateList extends WXVContainer<BounceRecyclerView> imp @WXComponentProp(name = Constants.Name.COLUMN_COUNT) public void setColumnCount(int columnCount){ - if(mDomObject.getColumnCount() != mColumnCount){ + if(getAttrs().getColumnCount() != mColumnCount){ updateRecyclerAttr(); WXRecyclerView wxRecyclerView = getHostView().getInnerView(); wxRecyclerView.initView(getContext(), mLayoutType,mColumnCount,mColumnGap,getOrientation()); @@ -809,7 +817,7 @@ public class WXRecyclerTemplateList extends WXVContainer<BounceRecyclerView> imp @WXComponentProp(name = Constants.Name.COLUMN_GAP) public void setColumnGap(float columnGap) throws InterruptedException { - if(mDomObject.getColumnGap() != mColumnGap) { + if(getAttrs().getColumnGap() != mColumnGap) { updateRecyclerAttr(); WXRecyclerView wxRecyclerView = getHostView().getInnerView(); wxRecyclerView.initView(getContext(), mLayoutType, mColumnCount, mColumnGap, getOrientation()); @@ -947,8 +955,8 @@ public class WXRecyclerTemplateList extends WXVContainer<BounceRecyclerView> imp || props.containsKey(Constants.Name.PADDING_LEFT) || props.containsKey(Constants.Name.PADDING_RIGHT)){ - if(mPaddingLeft !=mDomObject.getPadding().get(Spacing.LEFT) - || mPaddingRight !=mDomObject.getPadding().get(Spacing.RIGHT)) { + if(mPaddingLeft != getPadding().get(CSSShorthand.EDGE.LEFT) + || mPaddingRight != getPadding().get(CSSShorthand.EDGE.RIGHT)) { updateRecyclerAttr(); WXRecyclerView wxRecyclerView = getHostView().getInnerView(); wxRecyclerView.initView(getContext(), mLayoutType, mColumnCount, mColumnGap, getOrientation()); @@ -991,7 +999,7 @@ public class WXRecyclerTemplateList extends WXVContainer<BounceRecyclerView> imp offsetY = offsetY - offsetYCorrection; } getScrollStartEndHelper().onScrolled(offsetX, offsetY); - if(!getDomObject().getEvents().contains(Constants.Event.SCROLL)){ + if(!getEvents().contains(Constants.Event.SCROLL)){ return; } if (mFirstEvent) { @@ -1222,11 +1230,12 @@ public class WXRecyclerTemplateList extends WXVContainer<BounceRecyclerView> imp 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()); - } + // TODO +// if(component.getDomObject() instanceof WXCellDomObject +// && getDomObject() instanceof WXRecyclerDomObject){ +// WXCellDomObject domObject = (WXCellDomObject) component.getDomObject(); +// domObject.setRecyclerDomObject((WXRecyclerDomObject) getDomObject()); +// } component.setRenderData(cell.getRenderData()); return component; } @@ -1245,7 +1254,9 @@ public class WXRecyclerTemplateList extends WXVContainer<BounceRecyclerView> imp if(cell == getSourceTemplate(i)){ Object data = cellDataManager.listData.get(i); doRenderTemplate(cell, i); - Layouts.doSafeLayout(cell, new CSSLayoutContext()); + Layouts.doSafeLayout(cell +// , new CSSLayoutContext() + ); cell.setRenderData(data); break; } @@ -1307,8 +1318,8 @@ public class WXRecyclerTemplateList extends WXVContainer<BounceRecyclerView> imp return updates; } - public ArrayStack copyStack(CellRenderContext context, ArrayStack stack){ - ArrayStack onceStack = new ArrayStack(); + public ArrayStack copyStack(CellRenderContext context, ArrayStack stack){ + ArrayStack onceStack = new ArrayStack(); for(int index=0; index < stack.size(); index++) { Object value = stack.get(index); if(value instanceof Map){ @@ -1363,8 +1374,8 @@ public class WXRecyclerTemplateList extends WXVContainer<BounceRecyclerView> imp if(cell == null){ return -1; } - if(cell.getDomObject() != null && cell.getDomObject().getAttrs() != null){ - Object templateId = cell.getDomObject().getAttrs().get(Constants.Name.Recycler.SLOT_TEMPLATE_CASE); + if(cell.getAttrs() != null){ + Object templateId = cell.getAttrs().get(Constants.Name.Recycler.SLOT_TEMPLATE_CASE); String template = WXUtils.getString(templateId, null); if(cell == defaultTemplateCell){ template = defaultTemplateKey; @@ -1433,7 +1444,7 @@ public class WXRecyclerTemplateList extends WXVContainer<BounceRecyclerView> imp @Override public void onLoadMore(int offScreenY) { try { - String offset = getDomObject().getAttrs().getLoadMoreOffset(); + String offset = getAttrs().getLoadMoreOffset(); if (TextUtils.isEmpty(offset)) { offset = "0"; @@ -1511,10 +1522,10 @@ public class WXRecyclerTemplateList extends WXVContainer<BounceRecyclerView> imp if(!componentDisAppearList.containsKey(key)){ childLisener.notifyAppearStateChange(Constants.Event.APPEAR, direction); List<Object> eventArgs = null; - if(childLisener.getDomObject().getEvents() != null - && childLisener.getDomObject().getEvents().getEventBindingArgsValues() != null - && childLisener.getDomObject().getEvents().getEventBindingArgsValues().get(Constants.Event.DISAPPEAR) != null){ - eventArgs = childLisener.getDomObject().getEvents().getEventBindingArgsValues().get(Constants.Event.DISAPPEAR); + if(childLisener.getEvents() != null + && childLisener.getEvents().getEventBindingArgsValues() != null + && childLisener.getEvents().getEventBindingArgsValues().get(Constants.Event.DISAPPEAR) != null){ + eventArgs = childLisener.getEvents().getEventBindingArgsValues().get(Constants.Event.DISAPPEAR); } componentDisAppearList.put(key, eventArgs); } @@ -1554,7 +1565,7 @@ public class WXRecyclerTemplateList extends WXVContainer<BounceRecyclerView> imp if(eventWatchers == null || eventWatchers.size() == 0){ continue; } - WXEvent events = component.getDomObject().getEvents(); + WXEvent events = component.getEvents(); Set<Map.Entry<Integer, List<Object>>> eventWatcherEntries = eventWatchers.entrySet(); for(Map.Entry<Integer, List<Object>> eventWatcherEntry : eventWatcherEntries){ events.putEventBindingArgsValue(Constants.Event.DISAPPEAR, eventWatcherEntry.getValue()); @@ -1648,7 +1659,7 @@ public class WXRecyclerTemplateList extends WXVContainer<BounceRecyclerView> imp /** * find certain class type parent * */ - public WXComponent findParentType(WXComponent component, Class type){ + public WXComponent findParentType(WXComponent component, Class type){ if(component.getClass() == type){ return component; } @@ -1688,9 +1699,9 @@ public class WXRecyclerTemplateList extends WXVContainer<BounceRecyclerView> imp } List<WXComponent> componentList = new ArrayList<>(); WXVContainer container = child.getParent(); - if(container != null && (!(container instanceof WXRecyclerTemplateList))){ + if(container != null && (!(container instanceof WXRecyclerTemplateList))){ for(int i=0; i<container.getChildCount(); i++){ - WXComponent element = container.getChild(i); + WXComponent element = container.getChild(i); if(ref.equals(element.getRef())){ componentList.add(element); } @@ -1722,7 +1733,7 @@ public class WXRecyclerTemplateList extends WXVContainer<BounceRecyclerView> imp cache.isLoadIng = true; WXCell source = mTemplateSources.get(template); if(source != null){ - boolean allowPreload = WXUtils.getBoolean(source.getDomObject().getAttrs().get("preload"), true); + boolean allowPreload = WXUtils.getBoolean(source.getAttrs().get("preload"), true); if(allowPreload) { AsyncCellLoadTask asyncCellLoadTask = new AsyncCellLoadTask(template, source, this); asyncCellLoadTask.startTask(); http://git-wip-us.apache.org/repos/asf/incubator-weex/blob/2f8caedb/android/sdk/src/main/java/com/taobao/weex/ui/component/pesudo/OnActivePseudoListener.java ---------------------------------------------------------------------- diff --git a/android/sdk/src/main/java/com/taobao/weex/ui/component/pesudo/OnActivePseudoListener.java b/android/sdk/src/main/java/com/taobao/weex/ui/component/pesudo/OnActivePseudoListener.java deleted file mode 100644 index 989f9e9..0000000 --- a/android/sdk/src/main/java/com/taobao/weex/ui/component/pesudo/OnActivePseudoListener.java +++ /dev/null @@ -1,26 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ -package com.taobao.weex.ui.component.pesudo; - -/** - * Created by sospartan on 05/01/2017. - */ -public interface OnActivePseudoListener { - void updateActivePseudo(boolean isSet); -} http://git-wip-us.apache.org/repos/asf/incubator-weex/blob/2f8caedb/android/sdk/src/main/java/com/taobao/weex/ui/component/pesudo/OnActivePseudoListner.java ---------------------------------------------------------------------- diff --git a/android/sdk/src/main/java/com/taobao/weex/ui/component/pesudo/OnActivePseudoListner.java b/android/sdk/src/main/java/com/taobao/weex/ui/component/pesudo/OnActivePseudoListner.java new file mode 100644 index 0000000..961e3b8 --- /dev/null +++ b/android/sdk/src/main/java/com/taobao/weex/ui/component/pesudo/OnActivePseudoListner.java @@ -0,0 +1,26 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package com.taobao.weex.ui.component.pesudo; + +/** + * Created by sospartan on 05/01/2017. + */ +public interface OnActivePseudoListner { + void updateActivePseudo(boolean isSet); +} http://git-wip-us.apache.org/repos/asf/incubator-weex/blob/2f8caedb/android/sdk/src/main/java/com/taobao/weex/ui/component/pesudo/TouchActivePseudoListener.java ---------------------------------------------------------------------- diff --git a/android/sdk/src/main/java/com/taobao/weex/ui/component/pesudo/TouchActivePseudoListener.java b/android/sdk/src/main/java/com/taobao/weex/ui/component/pesudo/TouchActivePseudoListener.java index 7100144..8caf3f2 100644 --- a/android/sdk/src/main/java/com/taobao/weex/ui/component/pesudo/TouchActivePseudoListener.java +++ b/android/sdk/src/main/java/com/taobao/weex/ui/component/pesudo/TouchActivePseudoListener.java @@ -25,22 +25,22 @@ import android.view.View; * Created by sospartan on 05/01/2017. */ public class TouchActivePseudoListener implements View.OnTouchListener { - private OnActivePseudoListener mOnActivePseudoListener; + private OnActivePseudoListner mOnActivePseudoListner; private boolean mIsConsumeOnTouch; - public TouchActivePseudoListener(OnActivePseudoListener l, boolean consumeInTouch) { - mOnActivePseudoListener = l; + public TouchActivePseudoListener(OnActivePseudoListner l, boolean consumeInTouch) { + mOnActivePseudoListner = l; mIsConsumeOnTouch = consumeInTouch; } @Override public boolean onTouch(View v, MotionEvent event) { int action = event.getAction(); - if (mOnActivePseudoListener != null) { + if (mOnActivePseudoListner != null) { if (action == MotionEvent.ACTION_DOWN || action == MotionEvent.ACTION_POINTER_DOWN) { - mOnActivePseudoListener.updateActivePseudo(true); + mOnActivePseudoListner.updateActivePseudo(true); } else if (action == MotionEvent.ACTION_CANCEL || action == MotionEvent.ACTION_UP || action == MotionEvent.ACTION_POINTER_UP) { - mOnActivePseudoListener.updateActivePseudo(false); + mOnActivePseudoListner.updateActivePseudo(false); } } return mIsConsumeOnTouch; http://git-wip-us.apache.org/repos/asf/incubator-weex/blob/2f8caedb/android/sdk/src/main/java/com/taobao/weex/ui/config/ConfigComponentHolder.java ---------------------------------------------------------------------- diff --git a/android/sdk/src/main/java/com/taobao/weex/ui/config/ConfigComponentHolder.java b/android/sdk/src/main/java/com/taobao/weex/ui/config/ConfigComponentHolder.java index 151e76e..7a9948d 100644 --- a/android/sdk/src/main/java/com/taobao/weex/ui/config/ConfigComponentHolder.java +++ b/android/sdk/src/main/java/com/taobao/weex/ui/config/ConfigComponentHolder.java @@ -27,10 +27,10 @@ import com.taobao.weex.WXEnvironment; import com.taobao.weex.WXSDKInstance; import com.taobao.weex.WXSDKManager; import com.taobao.weex.bridge.Invoker; -import com.taobao.weex.dom.WXDomObject; import com.taobao.weex.ui.ComponentCreator; import com.taobao.weex.ui.IFComponentHolder; import com.taobao.weex.ui.SimpleComponentHolder; +import com.taobao.weex.ui.action.BasicComponentData; import com.taobao.weex.ui.component.WXComponent; import com.taobao.weex.ui.component.WXVContainer; import com.taobao.weex.utils.WXLogUtils; @@ -81,13 +81,13 @@ public class ConfigComponentHolder implements IFComponentHolder { @Override - public synchronized WXComponent createInstance(WXSDKInstance instance, WXDomObject node, WXVContainer parent) throws IllegalAccessException, InvocationTargetException, InstantiationException { + public synchronized WXComponent createInstance(WXSDKInstance instance, WXVContainer parent, BasicComponentData basicComponentData) throws IllegalAccessException, InvocationTargetException, InstantiationException { if(mClass == null || mClassLoader != instance.getContext().getClassLoader()){ mClass = WXSDKManager.getInstance().getClassLoaderAdapter().getComponentClass(mType, mClassName, instance); mClassLoader = instance.getContext().getClassLoader(); } ComponentCreator creator = new SimpleComponentHolder.ClazzComponentCreator(mClass); - WXComponent component = creator.createInstance(instance,node,parent); + WXComponent component = creator.createInstance(instance, parent, basicComponentData); component.bindHolder(this); return component; http://git-wip-us.apache.org/repos/asf/incubator-weex/blob/2f8caedb/android/sdk/src/main/java/com/taobao/weex/ui/config/ConfigModuleFactory.java ---------------------------------------------------------------------- diff --git a/android/sdk/src/main/java/com/taobao/weex/ui/config/ConfigModuleFactory.java b/android/sdk/src/main/java/com/taobao/weex/ui/config/ConfigModuleFactory.java index b36dc3c..4b8f973 100644 --- a/android/sdk/src/main/java/com/taobao/weex/ui/config/ConfigModuleFactory.java +++ b/android/sdk/src/main/java/com/taobao/weex/ui/config/ConfigModuleFactory.java @@ -18,7 +18,6 @@ */ package com.taobao.weex.ui.config; -import android.content.Context; import android.text.TextUtils; import com.alibaba.fastjson.JSONArray; http://git-wip-us.apache.org/repos/asf/incubator-weex/blob/2f8caedb/android/sdk/src/main/java/com/taobao/weex/ui/flat/FlatComponent.java ---------------------------------------------------------------------- diff --git a/android/sdk/src/main/java/com/taobao/weex/ui/flat/FlatComponent.java b/android/sdk/src/main/java/com/taobao/weex/ui/flat/FlatComponent.java index 2c0cc46..823da47 100644 --- a/android/sdk/src/main/java/com/taobao/weex/ui/flat/FlatComponent.java +++ b/android/sdk/src/main/java/com/taobao/weex/ui/flat/FlatComponent.java @@ -22,6 +22,7 @@ package com.taobao.weex.ui.flat; import android.support.annotation.NonNull; import android.support.annotation.RestrictTo; import android.support.annotation.RestrictTo.Scope; + import com.taobao.weex.ui.flat.widget.Widget; @RestrictTo(Scope.LIBRARY) @@ -29,5 +30,6 @@ public interface FlatComponent<T extends Widget> { boolean promoteToView(boolean checkAncestor); - @NonNull T getOrCreateFlatWidget(); + @NonNull + T getOrCreateFlatWidget(); } http://git-wip-us.apache.org/repos/asf/incubator-weex/blob/2f8caedb/android/sdk/src/main/java/com/taobao/weex/ui/flat/FlatGUIContext.java ---------------------------------------------------------------------- diff --git a/android/sdk/src/main/java/com/taobao/weex/ui/flat/FlatGUIContext.java b/android/sdk/src/main/java/com/taobao/weex/ui/flat/FlatGUIContext.java index 4004bc8..b161c78 100644 --- a/android/sdk/src/main/java/com/taobao/weex/ui/flat/FlatGUIContext.java +++ b/android/sdk/src/main/java/com/taobao/weex/ui/flat/FlatGUIContext.java @@ -7,7 +7,7 @@ * "License"); you may not use this file except in compliance * with the License. You may obtain a copy of the License at * - * http://www.apache.org/licenses/LICENSE-2.0 + * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, * software distributed under the License is distributed on an @@ -26,22 +26,22 @@ import android.support.annotation.RestrictTo.Scope; import android.support.v4.util.ArrayMap; import android.text.TextUtils; import android.view.View; + import com.taobao.weex.common.Constants.Name; import com.taobao.weex.common.Destroyable; -import com.taobao.weex.dom.ImmutableDomObject; import com.taobao.weex.dom.WXAttr; -import com.taobao.weex.dom.WXDomObject; import com.taobao.weex.dom.WXStyle; import com.taobao.weex.ui.component.WXComponent; import com.taobao.weex.ui.flat.widget.AndroidViewWidget; import com.taobao.weex.ui.flat.widget.Widget; + import java.util.Map; import java.util.Map.Entry; //TODO The constructor of FlatGUIContext should have a flag decide whether to enable flagGUI. @RestrictTo(Scope.LIBRARY) -public class FlatGUIContext implements Destroyable{ +public class FlatGUIContext implements Destroyable { private Map<WXComponent, WidgetContainer> mWidgetRegistry = new ArrayMap<>(); private Map<WXComponent, AndroidViewWidget> mViewWidgetRegistry = new ArrayMap<>(); @@ -53,16 +53,16 @@ public class FlatGUIContext implements Destroyable{ public void register(@NonNull WXComponent descendant, @NonNull WidgetContainer ancestor) { if (!(ancestor instanceof FlatComponent) || - ((FlatComponent) ancestor).promoteToView(true)) { + ((FlatComponent) ancestor).promoteToView(true)) { mWidgetRegistry.put(descendant, ancestor); } } - public void register(@NonNull WXComponent component, @NonNull AndroidViewWidget viewWidget){ + public void register(@NonNull WXComponent component, @NonNull AndroidViewWidget viewWidget) { mViewWidgetRegistry.put(component, viewWidget); } - public void register(@NonNull Widget widget, @NonNull WXComponent component){ + public void register(@NonNull Widget widget, @NonNull WXComponent component) { widgetToComponent.put(widget, component); } @@ -79,12 +79,12 @@ public class FlatGUIContext implements Destroyable{ } public boolean promoteToView(@NonNull WXComponent component, boolean checkAncestor, - @NonNull Class<? extends WXComponent<?>> expectedClass) { + @NonNull Class<? extends WXComponent<?>> expectedClass) { return !isFlatUIEnabled(component) || - !expectedClass.equals(component.getClass()) || - TextUtils.equals(component.getRef(), WXDomObject.ROOT) || - (checkAncestor && getFlatComponentAncestor(component) == null) || - checkComponent(component); + !expectedClass.equals(component.getClass()) || + TextUtils.equals(component.getRef(), WXComponent.ROOT) || + (checkAncestor && getFlatComponentAncestor(component) == null) || + checkComponent(component); } public @@ -102,42 +102,42 @@ public class FlatGUIContext implements Destroyable{ @Override @RestrictTo(Scope.LIBRARY) - public void destroy(){ + public void destroy() { widgetToComponent.clear(); - for(Entry<WXComponent, AndroidViewWidget> entry: mViewWidgetRegistry.entrySet()){ + for (Entry<WXComponent, AndroidViewWidget> entry : mViewWidgetRegistry.entrySet()) { entry.getValue().destroy(); } mViewWidgetRegistry.clear(); - for(Entry<WXComponent, WidgetContainer> entry:mWidgetRegistry.entrySet()){ + for (Entry<WXComponent, WidgetContainer> entry : mWidgetRegistry.entrySet()) { entry.getValue().unmountFlatGUI(); } mWidgetRegistry.clear(); } - private @Nullable WXComponent getComponent(@NonNull Widget widget){ + private @Nullable + WXComponent getComponent(@NonNull Widget widget) { return widgetToComponent.get(widget); } private boolean checkComponent(@NonNull WXComponent component) { boolean ret = false; - ImmutableDomObject domObject = component.getDomObject(); - if (domObject != null) { - WXStyle style = domObject.getStyles(); - WXAttr attr = domObject.getAttrs(); + if (component != null) { + WXStyle style = component.getStyles(); + WXAttr attr = component.getAttrs(); if (style.containsKey(Name.OPACITY) || - style.containsKey(Name.TRANSFORM) || - style.containsKey(Name.VISIBILITY) || - attr.containsKey(Name.ELEVATION) || - attr.containsKey(Name.ARIA_HIDDEN) || - attr.containsKey(Name.ARIA_LABEL) || - attr.containsKey(WXComponent.PROP_FIXED_SIZE) || - attr.containsKey(Name.DISABLED) || - style.isFixed() || - style.isSticky() || - !style.getPesudoStyles().isEmpty() || - domObject.getEvents().size() > 0) { + style.containsKey(Name.TRANSFORM) || + style.containsKey(Name.VISIBILITY) || + attr.containsKey(Name.ELEVATION) || + attr.containsKey(Name.ARIA_HIDDEN) || + attr.containsKey(Name.ARIA_LABEL) || + attr.containsKey(WXComponent.PROP_FIXED_SIZE) || + attr.containsKey(Name.DISABLED) || + style.isFixed() || + style.isSticky() || + !style.getPesudoStyles().isEmpty() || + component.getEvents().size() > 0) { ret = true; } } http://git-wip-us.apache.org/repos/asf/incubator-weex/blob/2f8caedb/android/sdk/src/main/java/com/taobao/weex/ui/flat/WidgetContainer.java ---------------------------------------------------------------------- diff --git a/android/sdk/src/main/java/com/taobao/weex/ui/flat/WidgetContainer.java b/android/sdk/src/main/java/com/taobao/weex/ui/flat/WidgetContainer.java index f68aaeb..0946800 100644 --- a/android/sdk/src/main/java/com/taobao/weex/ui/flat/WidgetContainer.java +++ b/android/sdk/src/main/java/com/taobao/weex/ui/flat/WidgetContainer.java @@ -7,7 +7,7 @@ * "License"); you may not use this file except in compliance * with the License. You may obtain a copy of the License at * - * http://www.apache.org/licenses/LICENSE-2.0 + * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, * software distributed under the License is distributed on an @@ -23,22 +23,24 @@ import android.support.annotation.RestrictTo; import android.support.annotation.RestrictTo.Scope; import android.util.Pair; import android.view.ViewGroup; + import com.taobao.weex.WXSDKInstance; -import com.taobao.weex.dom.WXDomObject; +import com.taobao.weex.ui.action.BasicComponentData; import com.taobao.weex.ui.component.WXComponent; import com.taobao.weex.ui.component.WXVContainer; import com.taobao.weex.ui.flat.widget.AndroidViewWidget; import com.taobao.weex.ui.flat.widget.Widget; + import java.util.LinkedList; import java.util.List; @RestrictTo(Scope.LIBRARY) public abstract class WidgetContainer<T extends ViewGroup> extends WXVContainer<T> { - protected List<Widget> widgets = new LinkedList<>(); + protected List<Widget> widgets; - public WidgetContainer(WXSDKInstance instance, WXDomObject node, WXVContainer parent) { - super(instance, node, parent); + public WidgetContainer(WXSDKInstance instance, WXVContainer parent, BasicComponentData basicComponentData) { + super(instance, parent, basicComponentData); } protected abstract void mountFlatGUI(); @@ -82,6 +84,9 @@ public abstract class WidgetContainer<T extends ViewGroup> extends WXVContainer< } private void addFlatChild(Widget widget, int index) { + if(widgets == null){ + widgets = new LinkedList<>(); + } if (index >= widgets.size()) { widgets.add(widget); } else { http://git-wip-us.apache.org/repos/asf/incubator-weex/blob/2f8caedb/android/sdk/src/main/java/com/taobao/weex/ui/flat/widget/AndroidViewWidget.java ---------------------------------------------------------------------- diff --git a/android/sdk/src/main/java/com/taobao/weex/ui/flat/widget/AndroidViewWidget.java b/android/sdk/src/main/java/com/taobao/weex/ui/flat/widget/AndroidViewWidget.java index 0610a8e..ad72054 100644 --- a/android/sdk/src/main/java/com/taobao/weex/ui/flat/widget/AndroidViewWidget.java +++ b/android/sdk/src/main/java/com/taobao/weex/ui/flat/widget/AndroidViewWidget.java @@ -25,24 +25,27 @@ import android.support.annotation.Nullable; import android.support.annotation.RestrictTo; import android.support.annotation.RestrictTo.Scope; import android.view.View; + import com.taobao.weex.common.Destroyable; import com.taobao.weex.ui.flat.FlatGUIContext; @RestrictTo(Scope.LIBRARY) public class AndroidViewWidget extends BaseWidget implements Destroyable { - private @Nullable View mView; + private @Nullable + View mView; + public AndroidViewWidget(@NonNull FlatGUIContext context) { super(context); } - public void setContentView(@Nullable View view){ + public void setContentView(@Nullable View view) { this.mView = view; } @Override public void setContentBox(int leftOffset, int topOffset, int rightOffset, int bottomOffset) { - if(mView!=null) { + if (mView != null) { mView.setPadding(leftOffset, topOffset, rightOffset, bottomOffset); invalidate(); } @@ -50,7 +53,7 @@ public class AndroidViewWidget extends BaseWidget implements Destroyable { @Override public void onDraw(@NonNull Canvas canvas) { - if(mView!=null) { + if (mView != null) { mView.draw(canvas); } } @@ -63,7 +66,8 @@ public class AndroidViewWidget extends BaseWidget implements Destroyable { } } - public @Nullable View getView() { + public @Nullable + View getView() { return mView; } http://git-wip-us.apache.org/repos/asf/incubator-weex/blob/2f8caedb/android/sdk/src/main/java/com/taobao/weex/ui/flat/widget/BaseWidget.java ---------------------------------------------------------------------- diff --git a/android/sdk/src/main/java/com/taobao/weex/ui/flat/widget/BaseWidget.java b/android/sdk/src/main/java/com/taobao/weex/ui/flat/widget/BaseWidget.java index 02432dc..09cd14a 100644 --- a/android/sdk/src/main/java/com/taobao/weex/ui/flat/widget/BaseWidget.java +++ b/android/sdk/src/main/java/com/taobao/weex/ui/flat/widget/BaseWidget.java @@ -115,14 +115,14 @@ abstract class BaseWidget implements Widget { Rect dirtyRegion = new Rect(borderBox); dirtyRegion.offset(offsetOfContainer.x, offsetOfContainer.y); View widgetContainer; - if ((widgetContainer = context.getWidgetContainerView(this)) != null) { + if (context != null && (widgetContainer = context.getWidgetContainerView(this)) != null) { widgetContainer.invalidate(dirtyRegion); } } protected void setCallback(@NonNull Drawable drawable) { View widgetContainer; - if ((widgetContainer = context.getWidgetContainerView(this)) != null) { + if (context != null && (widgetContainer = context.getWidgetContainerView(this)) != null) { drawable.setCallback(widgetContainer); } }
