Repository: incubator-weex
Updated Branches:
  refs/heads/0.11-dev 1d60c4150 -> fa1c8b085


* [android] update list add attr keep-scroll-position (#2793)

* * [android] update list add attr keep-scroll-position

* * [android] update list add attr animation

* * [android] update list

* * [android] update modify judgment

* * [android] add commit

* * [android] update formate code


Project: http://git-wip-us.apache.org/repos/asf/incubator-weex/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-weex/commit/58d009d6
Tree: http://git-wip-us.apache.org/repos/asf/incubator-weex/tree/58d009d6
Diff: http://git-wip-us.apache.org/repos/asf/incubator-weex/diff/58d009d6

Branch: refs/heads/0.11-dev
Commit: 58d009d63c97d94c6070311fa33800980822f060
Parents: 1d60c41
Author: xkli <569664...@qq.com>
Authored: Tue Feb 28 16:00:07 2017 +0800
Committer: sospartan zheng <sospar...@apache.org>
Committed: Tue Feb 28 16:00:07 2017 +0800

----------------------------------------------------------------------
 .../java/com/taobao/weex/common/Constants.java  |  8 +++
 .../ui/component/list/BasicListComponent.java   | 74 +++++++++++++++++++-
 2 files changed, 81 insertions(+), 1 deletion(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-weex/blob/58d009d6/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 f297b6d..e6e61e9 100755
--- a/android/sdk/src/main/java/com/taobao/weex/common/Constants.java
+++ b/android/sdk/src/main/java/com/taobao/weex/common/Constants.java
@@ -273,6 +273,8 @@ public class Constants {
 
     String POSITION = "position";
 
+    String KEEP_SCROLL_POSITION = "keepScrollPosition";
+
     String TEXT_DECORATION = "textDecoration";
     String TEXT_ALIGN = "textAlign";
     String FONT_WEIGHT = "fontWeight";
@@ -347,6 +349,9 @@ public class Constants {
     String RETURN_KEY_TYPE = "returnKeyType";
     String OFFSET = "offset";
     String ANIMATED = "animated";
+
+    String INSERT_CELL_ANIMATION = "insertAnimation";
+    String DELETE_CELL_ANIMATION = "deleteAnimation";
   }
 
   public interface Value {
@@ -381,6 +386,9 @@ public class Constants {
     String DIRECTION_RIGHT = "right";
     String DIRECTION_UP = "up";
     String DIRECTION_DOWN = "down";
+
+    String NONE = "none";
+    String DEFAULT = "default";
   }
 
   public interface Event {

http://git-wip-us.apache.org/repos/asf/incubator-weex/blob/58d009d6/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 65993f4..eb7fd78 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
@@ -231,6 +231,7 @@ import com.taobao.weex.annotation.JSMethod;
 import com.taobao.weex.common.Constants;
 import com.taobao.weex.common.OnWXScrollListener;
 import com.taobao.weex.common.WXRuntimeException;
+import com.taobao.weex.dom.ImmutableDomObject;
 import com.taobao.weex.dom.WXDomObject;
 import com.taobao.weex.ui.component.AppearanceHelper;
 import com.taobao.weex.ui.component.Scrollable;
@@ -288,6 +289,8 @@ public abstract class BasicListComponent<T extends 
ViewGroup & ListComponentView
   private int mOffsetAccuracy = 10;
   private Point mLastReport = new Point(-1, -1);
 
+  private RecyclerView.ItemAnimator mItemAnimator;
+
   /**
    * Map for storing component that is sticky.
    **/
@@ -407,6 +410,8 @@ public abstract class BasicListComponent<T extends 
ViewGroup & ListComponentView
       
bounceRecyclerView.getInnerView().addItemDecoration(parseTransforms(transforms));
     }
 
+    mItemAnimator=bounceRecyclerView.getInnerView().getItemAnimator();
+
     RecyclerViewBaseAdapter recyclerViewBaseAdapter = new 
RecyclerViewBaseAdapter<>(this);
     recyclerViewBaseAdapter.setHasStableIds(true);
     bounceRecyclerView.setRecyclerViewBaseAdapter(recyclerViewBaseAdapter);
@@ -752,11 +757,54 @@ public abstract class BasicListComponent<T extends 
ViewGroup & ListComponentView
     int adapterPosition = index == -1 ? mChildren.size() - 1 : index;
     T view = getHostView();
     if (view != null) {
-      view.getRecyclerViewBaseAdapter().notifyItemInserted(adapterPosition);
+      boolean isAddAnimation = isAddAnimation(child);
+      if (isAddAnimation) {
+        view.getInnerView().setItemAnimator(mItemAnimator);
+      } else {
+        view.getInnerView().setItemAnimator(null);
+      }
+      boolean isKeepScrollPosition = isKeepScrollPosition(child);
+      if (isKeepScrollPosition) {
+        view.getRecyclerViewBaseAdapter().notifyItemInserted(adapterPosition);
+      } else {
+        view.getRecyclerViewBaseAdapter().notifyItemChanged(adapterPosition);
+      }
     }
     relocateAppearanceHelper();
   }
 
+  /**
+   * To determine whether an animation is needed
+   * @param child
+   * @return
+   */
+  private boolean isAddAnimation(WXComponent child) {
+    ImmutableDomObject domObject = child.getDomObject();
+    if (domObject != null) {
+      Object attr = 
domObject.getAttrs().get(Constants.Name.INSERT_CELL_ANIMATION);
+      if (Constants.Value.DEFAULT.equals(attr)) {
+        return true;
+      }
+    }
+    return false;
+  }
+
+  /**
+   * Determine if the component needs to be fixed at the time of insertion
+   * @param child Need to insert the component
+   * @return fixed=true
+   */
+  private boolean isKeepScrollPosition(WXComponent child) {
+    ImmutableDomObject domObject = child.getDomObject();
+    if (domObject != null) {
+      Object attr = 
domObject.getAttrs().get(Constants.Name.KEEP_SCROLL_POSITION);
+      if (WXUtils.getBoolean(attr, false)) {
+        return true;
+      }
+    }
+    return false;
+  }
+
 
   private void relocateAppearanceHelper() {
     Iterator<Map.Entry<String, AppearanceHelper>> iterator = 
mAppearComponents.entrySet().iterator();
@@ -800,6 +848,14 @@ public abstract class BasicListComponent<T extends 
ViewGroup & ListComponentView
     if (view == null) {
       return;
     }
+
+    boolean isRemoveAnimation = isRemoveAnimation(child);
+    if (isRemoveAnimation) {
+      view.getInnerView().setItemAnimator(mItemAnimator);
+    } else {
+      view.getInnerView().setItemAnimator(null);
+    }
+
     view.getRecyclerViewBaseAdapter().notifyItemRemoved(index);
     if (WXEnvironment.isApkDebugable()) {
       WXLogUtils.d(TAG, "removeChild child at " + index);
@@ -807,6 +863,22 @@ public abstract class BasicListComponent<T extends 
ViewGroup & ListComponentView
     super.remove(child, destroy);
   }
 
+  /**
+   * To determine whether an animation is needed
+   * @param child
+   * @return
+   */
+  private boolean isRemoveAnimation(WXComponent child) {
+    ImmutableDomObject domObject = child.getDomObject();
+    if (domObject != null) {
+      Object attr = 
domObject.getAttrs().get(Constants.Name.DELETE_CELL_ANIMATION);
+      if (Constants.Value.DEFAULT.equals(attr)) {
+        return true;
+      }
+    }
+    return false;
+  }
+
 
   @Override
   public void computeVisiblePointInViewCoordinate(PointF pointF) {

Reply via email to