You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@weex.apache.org by mi...@apache.org on 2018/03/01 08:13:30 UTC
[1/3] incubator-weex git commit: [WEEX-218][android] support leftGap
and rightGap for waterfall component,
template list orientation support updateAttrs
Repository: incubator-weex
Updated Branches:
refs/heads/master 9d11a5da0 -> 118abd37d
[WEEX-218][android] support leftGap and rightGap for waterfall component, template list orientation support updateAttrs
Project: http://git-wip-us.apache.org/repos/asf/incubator-weex/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-weex/commit/b4421229
Tree: http://git-wip-us.apache.org/repos/asf/incubator-weex/tree/b4421229
Diff: http://git-wip-us.apache.org/repos/asf/incubator-weex/diff/b4421229
Branch: refs/heads/master
Commit: b4421229eb9107d29ef9e27f52d4316447375b5f
Parents: de40fe1
Author: jianbai.gbj <ji...@alibaba-inc.com>
Authored: Tue Feb 13 11:36:18 2018 +0800
Committer: jianbai.gbj <ji...@alibaba-inc.com>
Committed: Tue Feb 13 11:36:18 2018 +0800
----------------------------------------------------------------------
.../java/com/taobao/weex/common/Constants.java | 2 +
.../taobao/weex/dom/WXRecyclerDomObject.java | 49 ++++++++++++--
.../ui/component/list/BasicListComponent.java | 2 +
.../ui/component/list/GapItemDecoration.java | 71 ++++++++++++++++++++
.../weex/ui/component/list/WXListComponent.java | 34 ++++++++++
.../list/template/WXRecyclerTemplateList.java | 18 +++++
6 files changed, 170 insertions(+), 6 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-weex/blob/b4421229/android/sdk/src/main/java/com/taobao/weex/common/Constants.java
----------------------------------------------------------------------
diff --git a/android/sdk/src/main/java/com/taobao/weex/common/Constants.java b/android/sdk/src/main/java/com/taobao/weex/common/Constants.java
index 64b59c8..6f74f48 100644
--- a/android/sdk/src/main/java/com/taobao/weex/common/Constants.java
+++ b/android/sdk/src/main/java/com/taobao/weex/common/Constants.java
@@ -123,6 +123,8 @@ public class Constants {
String COLUMN_WIDTH= "columnWidth";
String COLUMN_COUNT= "columnCount";
String COLUMN_GAP= "columnGap";
+ String LEFT_GAP= "leftGap";
+ String RIGHT_GAP= "rightGap";
String SHOW_SCROLLBAR= "showScrollbar";
String OVERFLOW = "overflow";
String TYPE = "type";
http://git-wip-us.apache.org/repos/asf/incubator-weex/blob/b4421229/android/sdk/src/main/java/com/taobao/weex/dom/WXRecyclerDomObject.java
----------------------------------------------------------------------
diff --git a/android/sdk/src/main/java/com/taobao/weex/dom/WXRecyclerDomObject.java b/android/sdk/src/main/java/com/taobao/weex/dom/WXRecyclerDomObject.java
index 5fe245b..daf3850 100644
--- a/android/sdk/src/main/java/com/taobao/weex/dom/WXRecyclerDomObject.java
+++ b/android/sdk/src/main/java/com/taobao/weex/dom/WXRecyclerDomObject.java
@@ -25,6 +25,7 @@ import com.taobao.weex.common.Constants;
import com.taobao.weex.dom.flex.Spacing;
import com.taobao.weex.ui.component.WXBasicComponentType;
import com.taobao.weex.utils.WXLogUtils;
+import com.taobao.weex.utils.WXUtils;
import com.taobao.weex.utils.WXViewUtils;
import java.util.ArrayList;
@@ -45,12 +46,17 @@ public class WXRecyclerDomObject extends WXDomObject{
private float mAvailableWidth = 0;
private boolean mIsPreCalculateCellWidth =false;
+ private float mLeftGap = 0;
+ private float mRightGap = 0;
+
+ private float[] spanOffsets;
+
/**cell-slot not on the tree */
private List<WXCellDomObject> cellList;
public float getAvailableWidth() {
- return WXViewUtils.getRealPxByWidth(mAvailableWidth,getViewPortWidth());
+ return WXViewUtils.getRealPxByWidth(mAvailableWidth, getViewPortWidth());
}
public int getLayoutType(){
@@ -58,9 +64,10 @@ public class WXRecyclerDomObject extends WXDomObject{
}
public float getColumnGap() {
- return WXViewUtils.getRealPxByWidth(mColumnGap,getViewPortWidth());
+ return WXViewUtils.getRealPxByWidth(mColumnGap, getViewPortWidth());
}
+
public int getColumnCount() {
return mColumnCount;
}
@@ -68,6 +75,15 @@ public class WXRecyclerDomObject extends WXDomObject{
public float getColumnWidth() {
return WXViewUtils.getRealPxByWidth(mColumnWidth,getViewPortWidth());
}
+
+ public float getLeftGap() {
+ return WXViewUtils.getRealPxByWidth(mLeftGap,getViewPortWidth());
+ }
+
+ public float getRightGap() {
+ return WXViewUtils.getRealPxByWidth(mRightGap,getViewPortWidth());
+ }
+
@Override
public void add(WXDomObject child, int index) {
if(WXBasicComponentType.CELL_SLOT.equals(child.getType())
@@ -129,12 +145,17 @@ public class WXRecyclerDomObject extends WXDomObject{
return width;
}
+
+
+
public void preCalculateCellWidth(){
if (getAttrs() != null) {
mColumnCount = getAttrs().getColumnCount();
mColumnWidth = getAttrs().getColumnWidth();
mColumnGap = getAttrs().getColumnGap();
+ mLeftGap = WXUtils.getFloat(getAttrs().get(Constants.Name.LEFT_GAP),0.0f);
+ mRightGap = WXUtils.getFloat(getAttrs().get(Constants.Name.RIGHT_GAP),0.0f);
mAvailableWidth = getStyleWidth()-getPadding().get(Spacing.LEFT)-getPadding().get(Spacing.RIGHT);
mAvailableWidth = WXViewUtils.getWebPxByWidth(mAvailableWidth,getViewPortWidth());
@@ -142,21 +163,22 @@ public class WXRecyclerDomObject extends WXDomObject{
if (Constants.Value.AUTO == mColumnCount && Constants.Value.AUTO == mColumnWidth) {
mColumnCount = Constants.Value.COLUMN_COUNT_NORMAL;
} else if (Constants.Value.AUTO == mColumnWidth && Constants.Value.AUTO != mColumnCount) {
- mColumnWidth = (mAvailableWidth - ((mColumnCount - 1) * mColumnGap)) / mColumnCount;
+ mColumnWidth = (mAvailableWidth - mLeftGap - mRightGap - ((mColumnCount - 1) * mColumnGap)) / mColumnCount;
mColumnWidth = mColumnWidth > 0 ? mColumnWidth :0;
} else if (Constants.Value.AUTO != mColumnWidth && Constants.Value.AUTO == mColumnCount) {
mColumnCount = Math.round((mAvailableWidth + mColumnGap) / (mColumnWidth + mColumnGap)-0.5f);
mColumnCount = mColumnCount > 0 ? mColumnCount :1;
if (mColumnCount <= 0)
mColumnCount = Constants.Value.COLUMN_COUNT_NORMAL;
- mColumnWidth =((mAvailableWidth + mColumnGap) / mColumnCount) - mColumnGap;
+ mColumnWidth =((mAvailableWidth + mColumnGap - mLeftGap - mRightGap) / mColumnCount) - mColumnGap;
} else if(Constants.Value.AUTO != mColumnWidth && Constants.Value.AUTO != mColumnCount){
- int columnCount = Math.round((mAvailableWidth + mColumnGap) / (mColumnWidth + mColumnGap)-0.5f);
+ int columnCount = Math.round((mAvailableWidth + mColumnGap - mLeftGap - mRightGap) / (mColumnWidth + mColumnGap)-0.5f);
mColumnCount = columnCount > mColumnCount ? mColumnCount :columnCount;
if (mColumnCount <= 0)
mColumnCount = Constants.Value.COLUMN_COUNT_NORMAL;
- mColumnWidth= ((mAvailableWidth + mColumnGap) / mColumnCount) - mColumnGap;
+ mColumnWidth = ((mAvailableWidth + mColumnGap - mLeftGap - mRightGap) / mColumnCount) - mColumnGap;
}
+ calcSpanOffset();
mIsPreCalculateCellWidth = true;
if(WXEnvironment.isApkDebugable()) {
WXLogUtils.d("preCalculateCellWidth mColumnGap :" + mColumnGap + " mColumnWidth:" + mColumnWidth + " mColumnCount:" + mColumnCount);
@@ -238,6 +260,21 @@ public class WXRecyclerDomObject extends WXDomObject{
return domObject;
}
+ public void calcSpanOffset(){
+ if(mLeftGap > 0 || mRightGap > 0){
+ if(spanOffsets == null || spanOffsets.length != mColumnCount){
+ spanOffsets = new float[mColumnCount];
+ }
+ for(int i=0; i<mColumnCount; i++){
+ spanOffsets[i] = mLeftGap + i*((mColumnWidth + mColumnGap) - (mAvailableWidth + mColumnGap)/mColumnCount);
+ }
+ }
+ }
+
+ public float[] getSpanOffsets() {
+ return spanOffsets;
+ }
+
public List<WXCellDomObject> getCellList() {
return cellList;
}
http://git-wip-us.apache.org/repos/asf/incubator-weex/blob/b4421229/android/sdk/src/main/java/com/taobao/weex/ui/component/list/BasicListComponent.java
----------------------------------------------------------------------
diff --git a/android/sdk/src/main/java/com/taobao/weex/ui/component/list/BasicListComponent.java b/android/sdk/src/main/java/com/taobao/weex/ui/component/list/BasicListComponent.java
index 2ea3254..59a4f4b 100644
--- a/android/sdk/src/main/java/com/taobao/weex/ui/component/list/BasicListComponent.java
+++ b/android/sdk/src/main/java/com/taobao/weex/ui/component/list/BasicListComponent.java
@@ -114,6 +114,8 @@ public abstract class BasicListComponent<T extends ViewGroup & ListComponentView
protected int mColumnCount = 1;
protected float mColumnGap = 0;
protected float mColumnWidth = 0;
+ protected float mLeftGap = 0;
+ protected float mRightGap = 0;
private int mOffsetAccuracy = 10;
private Point mLastReport = new Point(-1, -1);
http://git-wip-us.apache.org/repos/asf/incubator-weex/blob/b4421229/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
new file mode 100644
index 0000000..a721a4e
--- /dev/null
+++ b/android/sdk/src/main/java/com/taobao/weex/ui/component/list/GapItemDecoration.java
@@ -0,0 +1,71 @@
+/**
+ * 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.list;
+
+import android.graphics.Rect;
+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;
+
+/**
+ * Created by furture on 2018/2/12.
+ * recyclerview's height is layout width + column gap,
+ * so the the offset should include, leftGap and rightGap is via this
+ */
+public class GapItemDecoration extends RecyclerView.ItemDecoration {
+
+ private WXListComponent listComponent;
+
+ public GapItemDecoration(WXListComponent listComponent) {
+ this.listComponent = listComponent;
+ }
+
+ @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;
+ }
+ }
+ }
+}
http://git-wip-us.apache.org/repos/asf/incubator-weex/blob/b4421229/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 046903b..302e413 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
@@ -87,6 +87,9 @@ public class WXListComponent extends BasicListComponent<BounceRecyclerView> {
bounceRecyclerView.getSwipeLayout().setNestedScrollingEnabled(true);
}
}
+ if(mRecyclerDom.getSpanOffsets() != null){
+ bounceRecyclerView.getInnerView().addItemDecoration(new GapItemDecoration(this));
+ }
return bounceRecyclerView;
}
@@ -135,6 +138,31 @@ public class WXListComponent extends BasicListComponent<BounceRecyclerView> {
mColumnWidth = mRecyclerDom.getColumnWidth();
mPaddingLeft = mRecyclerDom.getPadding().get(Spacing.LEFT);
mPaddingRight = mRecyclerDom.getPadding().get(Spacing.RIGHT);
+ mLeftGap = mRecyclerDom.getLeftGap();
+ mRightGap = mRecyclerDom.getRightGap();
+ mRecyclerDom.preCalculateCellWidth();
+ }
+ }
+
+ @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());
}
}
@@ -223,6 +251,10 @@ public class WXListComponent extends BasicListComponent<BounceRecyclerView> {
}
}
+ public WXRecyclerDomObject getRecyclerDom() {
+ return mRecyclerDom;
+ }
+
public void remove(WXComponent child, boolean destroy) {
super.remove(child, destroy);
if (child instanceof WXLoading) {
@@ -231,4 +263,6 @@ public class WXListComponent extends BasicListComponent<BounceRecyclerView> {
getHostView().removeHeaderView(child);
}
}
+
+
}
http://git-wip-us.apache.org/repos/asf/incubator-weex/blob/b4421229/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 d8200a2..879b7b4 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
@@ -726,6 +726,11 @@ public class WXRecyclerTemplateList extends WXVContainer<BounceRecyclerView> imp
boolean scrollable = WXUtils.getBoolean(param, true);
setScrollable(scrollable);
return true;
+ case Constants.Name.SCROLL_DIRECTION:
+ if(param != null) {
+ setScrollDirection(param.toString());
+ }
+ return true;
case Constants.Name.SHOW_SCROLLBAR:
Boolean result = WXUtils.getBoolean(param,null);
if (result != null)
@@ -757,6 +762,19 @@ public class WXRecyclerTemplateList extends WXVContainer<BounceRecyclerView> imp
mColumnWidth = mDomObject.getColumnWidth();
mPaddingLeft =mDomObject.getPadding().get(Spacing.LEFT);
mPaddingRight =mDomObject.getPadding().get(Spacing.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());
+
+ }
}
@WXComponentProp(name = Constants.Name.COLUMN_WIDTH)
[2/3] incubator-weex git commit: [WEEX-218][android] support leftGap
and rightGap for waterfall component,
template list orientation support updateAttrs
Posted by mi...@apache.org.
[WEEX-218][android] support leftGap and rightGap for waterfall component, template list orientation support updateAttrs
Project: http://git-wip-us.apache.org/repos/asf/incubator-weex/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-weex/commit/ff71bab4
Tree: http://git-wip-us.apache.org/repos/asf/incubator-weex/tree/ff71bab4
Diff: http://git-wip-us.apache.org/repos/asf/incubator-weex/diff/ff71bab4
Branch: refs/heads/master
Commit: ff71bab4a217256d681f3dec26a6e05a2814f892
Parents: b442122
Author: jianbai.gbj <ji...@alibaba-inc.com>
Authored: Tue Feb 13 13:19:47 2018 +0800
Committer: jianbai.gbj <ji...@alibaba-inc.com>
Committed: Tue Feb 13 13:19:47 2018 +0800
----------------------------------------------------------------------
.../java/com/taobao/weex/ui/component/list/WXListComponent.java | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-weex/blob/ff71bab4/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 302e413..fb5597f 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
@@ -87,7 +87,7 @@ public class WXListComponent extends BasicListComponent<BounceRecyclerView> {
bounceRecyclerView.getSwipeLayout().setNestedScrollingEnabled(true);
}
}
- if(mRecyclerDom.getSpanOffsets() != null){
+ if(mRecyclerDom != null && mRecyclerDom.getSpanOffsets() != null){
bounceRecyclerView.getInnerView().addItemDecoration(new GapItemDecoration(this));
}
return bounceRecyclerView;
[3/3] incubator-weex git commit: Merge remote-tracking branch
'upstream/pr1031' into apache-master
Posted by mi...@apache.org.
Merge remote-tracking branch 'upstream/pr1031' into apache-master
Project: http://git-wip-us.apache.org/repos/asf/incubator-weex/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-weex/commit/118abd37
Tree: http://git-wip-us.apache.org/repos/asf/incubator-weex/tree/118abd37
Diff: http://git-wip-us.apache.org/repos/asf/incubator-weex/diff/118abd37
Branch: refs/heads/master
Commit: 118abd37d52485b878da9eab5ff431a29053104a
Parents: 9d11a5d ff71bab
Author: misakuo <mi...@apache.org>
Authored: Thu Mar 1 16:13:14 2018 +0800
Committer: misakuo <mi...@apache.org>
Committed: Thu Mar 1 16:13:14 2018 +0800
----------------------------------------------------------------------
.../java/com/taobao/weex/common/Constants.java | 2 +
.../taobao/weex/dom/WXRecyclerDomObject.java | 49 ++++++++++++--
.../ui/component/list/BasicListComponent.java | 2 +
.../ui/component/list/GapItemDecoration.java | 71 ++++++++++++++++++++
.../weex/ui/component/list/WXListComponent.java | 34 ++++++++++
.../list/template/WXRecyclerTemplateList.java | 18 +++++
6 files changed, 170 insertions(+), 6 deletions(-)
----------------------------------------------------------------------