YorkShen closed pull request #1323: [WEEX-502][Android]Weex Template List 
Support Animation & queryElement
URL: https://github.com/apache/incubator-weex/pull/1323
 
 
   

This is a PR merged from a forked repository.
As GitHub hides the original diff on merge, it is displayed below for
the sake of provenance:

As this is a foreign pull request (from a fork), the diff is supplied
below (as it won't show otherwise due to GitHub magic):

diff --git 
a/android/sdk/src/main/java/com/taobao/weex/ui/action/GraphicActionAnimation.java
 
b/android/sdk/src/main/java/com/taobao/weex/ui/action/GraphicActionAnimation.java
index 633d5c2cdb..40ae52e362 100644
--- 
a/android/sdk/src/main/java/com/taobao/weex/ui/action/GraphicActionAnimation.java
+++ 
b/android/sdk/src/main/java/com/taobao/weex/ui/action/GraphicActionAnimation.java
@@ -47,6 +47,7 @@
 import com.taobao.weex.ui.animation.WXAnimationModule;
 import com.taobao.weex.ui.animation.WidthProperty;
 import com.taobao.weex.ui.component.WXComponent;
+import com.taobao.weex.ui.component.list.template.TemplateDom;
 import com.taobao.weex.ui.view.border.BorderDrawable;
 import com.taobao.weex.utils.SingleFunctionParser;
 import com.taobao.weex.utils.WXLogUtils;
@@ -103,7 +104,13 @@ public void executeAction() {
 
     WXComponent component = 
WXSDKManager.getInstance().getWXRenderManager().getWXComponent(getPageId(), 
getRef());
     if (component == null) {
-      return;
+      if(!TemplateDom.isVirtualDomRef(getRef())){
+        return;
+      }
+      component = TemplateDom.findVirtualComponentByVRef(getPageId(), 
getRef());
+      if(component == null){
+        return;
+      }
     }
 
     WXSDKInstance instance = 
WXSDKManager.getInstance().getWXRenderManager().getWXSDKInstance(getPageId());
@@ -122,6 +129,8 @@ public void executeAction() {
     }
   }
 
+
+
   private void startAnimation(@NonNull WXSDKInstance instance, @Nullable 
WXComponent component) {
     if (component != null) {
       if (mAnimationBean != null) {
@@ -270,5 +279,4 @@ public Float map(String raw) {
     }
     return null;
   }
-
 }
\ No newline at end of file
diff --git 
a/android/sdk/src/main/java/com/taobao/weex/ui/animation/WXAnimationModule.java 
b/android/sdk/src/main/java/com/taobao/weex/ui/animation/WXAnimationModule.java
index 11b02bcc3f..441c410745 100644
--- 
a/android/sdk/src/main/java/com/taobao/weex/ui/animation/WXAnimationModule.java
+++ 
b/android/sdk/src/main/java/com/taobao/weex/ui/animation/WXAnimationModule.java
@@ -27,6 +27,7 @@
 import com.taobao.weex.common.WXModule;
 import com.taobao.weex.ui.action.GraphicActionAnimation;
 import com.taobao.weex.ui.component.WXComponent;
+import com.taobao.weex.ui.component.list.template.TemplateDom;
 
 public class WXAnimationModule extends WXModule {
 
@@ -40,6 +41,9 @@ public void transition(@Nullable String ref, @Nullable String 
animation, @Nullab
     }
   }
 
+
+ 
+
   //add by moxun on 12/26/2016
   public static class AnimationHolder {
 
diff --git 
a/android/sdk/src/main/java/com/taobao/weex/ui/component/WXComponent.java 
b/android/sdk/src/main/java/com/taobao/weex/ui/component/WXComponent.java
index 220bb7ced0..d25f866442 100644
--- a/android/sdk/src/main/java/com/taobao/weex/ui/component/WXComponent.java
+++ b/android/sdk/src/main/java/com/taobao/weex/ui/component/WXComponent.java
@@ -516,7 +516,7 @@ public void onCallback(Object result) {
     };
     try{
       fireEvent(type, params, null, callback);
-      waitLatch.await(10, TimeUnit.MILLISECONDS);
+      waitLatch.await(50, TimeUnit.MILLISECONDS);
       return  callback;
     }catch (Exception e){
       if(WXEnvironment.isApkDebugable()){
diff --git 
a/android/sdk/src/main/java/com/taobao/weex/ui/component/WXVContainer.java 
b/android/sdk/src/main/java/com/taobao/weex/ui/component/WXVContainer.java
index ee64b98c5c..a3a04fa916 100644
--- a/android/sdk/src/main/java/com/taobao/weex/ui/component/WXVContainer.java
+++ b/android/sdk/src/main/java/com/taobao/weex/ui/component/WXVContainer.java
@@ -49,7 +49,6 @@
   private static final String TAG = "WXVContainer";
   protected ArrayList<WXComponent> mChildren = new ArrayList<>();
   private BoxShadowHost mBoxShadowHost;
-  private  boolean requestDisallowInterceptTouchEvent = false;
 
   @Deprecated
   public WXVContainer(WXSDKInstance instance, WXVContainer parent, String 
instanceId, boolean isLazy, BasicComponentData basicComponentData) {
@@ -544,14 +543,14 @@ private void doViewTreeRecycleImageView(ViewGroup 
viewGroup, boolean isRelease){
 
 
   public void requestDisallowInterceptTouchEvent(boolean 
requestDisallowInterceptTouchEvent) {
-    if(this.requestDisallowInterceptTouchEvent != 
requestDisallowInterceptTouchEvent){
-      this.requestDisallowInterceptTouchEvent = 
requestDisallowInterceptTouchEvent;
-      if(mGesture != null){
-        
mGesture.setRequestDisallowInterceptTouchEvent(requestDisallowInterceptTouchEvent);
-      }
-      if(getParent() != null){
-        
getParent().requestDisallowInterceptTouchEvent(requestDisallowInterceptTouchEvent);
+    if(mGesture != null){
+      if(mGesture.isRequestDisallowInterceptTouchEvent()){
+        return;
       }
+      
mGesture.setRequestDisallowInterceptTouchEvent(requestDisallowInterceptTouchEvent);
+    }
+    if(getParent() != null){
+      
getParent().requestDisallowInterceptTouchEvent(requestDisallowInterceptTouchEvent);
     }
   }
 
diff --git 
a/android/sdk/src/main/java/com/taobao/weex/ui/component/binding/AsynLayoutTask.java
 
b/android/sdk/src/main/java/com/taobao/weex/ui/component/binding/AsynLayoutTask.java
index 9f9992568c..02a848659a 100644
--- 
a/android/sdk/src/main/java/com/taobao/weex/ui/component/binding/AsynLayoutTask.java
+++ 
b/android/sdk/src/main/java/com/taobao/weex/ui/component/binding/AsynLayoutTask.java
@@ -21,6 +21,7 @@
 import android.os.AsyncTask;
 
 import com.taobao.weex.ui.component.WXComponent;
+import com.taobao.weex.ui.component.list.template.TemplateDom;
 import com.taobao.weex.ui.component.list.template.TemplateViewHolder;
 
 /**
@@ -54,6 +55,9 @@ protected void onPostExecute(Void aVoid) {
         if(position == templateViewHolder.getHolderPosition()) {
             if(component.getInstance() != null && 
!component.getInstance().isDestroy()) {
                 Layouts.setLayout(component, false);
+                if(templateViewHolder.getHolderPosition() >= 0){
+                    
templateViewHolder.getTemplateList().fireEvent("_attach_slot", 
TemplateDom.findAllComponentRefs(templateViewHolder.getTemplateList().getRef(), 
position, component));
+                }
             }
         }
     }
diff --git 
a/android/sdk/src/main/java/com/taobao/weex/ui/component/binding/Layouts.java 
b/android/sdk/src/main/java/com/taobao/weex/ui/component/binding/Layouts.java
index bdbcea9d68..9320bce6d9 100644
--- 
a/android/sdk/src/main/java/com/taobao/weex/ui/component/binding/Layouts.java
+++ 
b/android/sdk/src/main/java/com/taobao/weex/ui/component/binding/Layouts.java
@@ -28,10 +28,12 @@
 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.component.list.template.TemplateDom;
 import com.taobao.weex.ui.component.list.template.TemplateViewHolder;
 import com.taobao.weex.ui.component.list.template.WXRecyclerTemplateList;
 import com.taobao.weex.ui.component.list.template.jni.NativeRenderObjectUtils;
 import com.taobao.weex.utils.WXLogUtils;
+import com.taobao.weex.utils.WXUtils;
 
 /**
  * Created by furture on 2017/8/21.
@@ -55,6 +57,9 @@ public static void doLayoutAsync(final TemplateViewHolder 
templateViewHolder, bo
         }else{
             doLayoutOnly(component, templateViewHolder);
             setLayout(component, false);
+            if(templateViewHolder.getHolderPosition() >= 0){
+                templateViewHolder.getTemplateList().fireEvent("_attach_slot", 
TemplateDom.findAllComponentRefs(templateViewHolder.getTemplateList().getRef(), 
position, component));
+            }
         }
 
     }
@@ -106,6 +111,11 @@ public static final void setLayout(WXComponent component, 
boolean force){
         if(component.isWaste()){
             return;
         }
+        if(component.getAttrs().containsKey(TemplateDom.KEY_RESET_ANIMATION)){
+            
if(WXUtils.getBoolean(component.getAttrs().get(TemplateDom.KEY_RESET_ANIMATION),
 true).booleanValue()){
+                TemplateDom.resetAnimaiton(component.getHostView());
+            }
+        }
         long ptr = component.getRenderObjectPtr();
         if(NativeRenderObjectUtils.nativeRenderObjectHasNewLayout(ptr)){
             NativeRenderObjectUtils.nativeRenderObjectUpdateComponent(ptr, 
component);
diff --git 
a/android/sdk/src/main/java/com/taobao/weex/ui/component/binding/Statements.java
 
b/android/sdk/src/main/java/com/taobao/weex/ui/component/binding/Statements.java
index 2e1cb92d47..e19ff8b9d9 100644
--- 
a/android/sdk/src/main/java/com/taobao/weex/ui/component/binding/Statements.java
+++ 
b/android/sdk/src/main/java/com/taobao/weex/ui/component/binding/Statements.java
@@ -47,6 +47,7 @@
 import com.taobao.weex.ui.component.list.WXCell;
 import com.taobao.weex.ui.component.list.template.CellDataManager;
 import com.taobao.weex.ui.component.list.template.CellRenderContext;
+import com.taobao.weex.ui.component.list.template.TemplateDom;
 import com.taobao.weex.ui.component.list.template.VirtualComponentLifecycle;
 import com.taobao.weex.ui.component.list.template.WXRecyclerTemplateList;
 import com.taobao.weex.ui.component.list.template.jni.NativeRenderObjectUtils;
@@ -356,7 +357,8 @@ private static void 
doBindingAttrsEventAndRenderChildNode(WXComponent component,
         ArrayStack stack = context.stack;
 
 
-
+        String virtualComponentId = null;
+        boolean callVirtualComponentAttach = false;
         if(attr.get(ELUtils.IS_COMPONENT_ROOT) != null
                 && WXUtils.getBoolean(attr.get(ELUtils.IS_COMPONENT_ROOT), 
false)){
             if(attr.get(ELUtils.COMPONENT_PROPS) != null
@@ -364,7 +366,7 @@ private static void 
doBindingAttrsEventAndRenderChildNode(WXComponent component,
                  String compoentId = (String) 
attr.get(CellDataManager.SUB_COMPONENT_TEMPLATE_ID);
                 Object compoentData = null;
                 if(!TextUtils.isEmpty(compoentId)){
-                    String virtualComponentId =  
context.getRenderState().getVirtualComponentIds().get(component.getViewTreeKey());
+                   virtualComponentId =  
context.getRenderState().getVirtualComponentIds().get(component.getViewTreeKey());
                    if(virtualComponentId == null){ //none virtualComponentId, 
create and do attach
                         virtualComponentId =  
CellDataManager.createVirtualComponentId(context.templateList.getRef(),
                                 component.getViewTreeKey(), 
context.templateList.getItemId(context.position));
@@ -381,8 +383,7 @@ private static void 
doBindingAttrsEventAndRenderChildNode(WXComponent component,
                         compoentData  =  props;
                         
context.getRenderState().getVirtualComponentIds().put(component.getViewTreeKey(),
 virtualComponentId);
                         
context.templateList.getCellDataManager().createVirtualComponentData(context.position,
 virtualComponentId, compoentData);
-                        //create virtual componentId
-                        
WXBridgeManager.getInstance().asyncCallJSEventVoidResult(WXBridgeManager.METHD_COMPONENT_HOOK_SYNC,
 component.getInstanceId(), null, virtualComponentId, 
VirtualComponentLifecycle.LIFECYCLE, VirtualComponentLifecycle.ATTACH, null);
+                         callVirtualComponentAttach = true; // when first 
create virtual compoent, call create
                      }else{ // get virtual component data check has dirty's 
update
                        compoentData = 
context.getRenderState().getVirtualComponentDatas().get(virtualComponentId);
                        if(context.getRenderState().isHasDataUpdate()){
@@ -446,7 +447,13 @@ private static void 
doBindingAttrsEventAndRenderChildNode(WXComponent component,
         if(stack != context.stack){
             context.stack = stack;
         }
-    }
+        //create virtual componentId
+        if(callVirtualComponentAttach && virtualComponentId != null){
+            
WXBridgeManager.getInstance().asyncCallJSEventVoidResult(WXBridgeManager.METHD_COMPONENT_HOOK_SYNC,
 component.getInstanceId(), null, virtualComponentId, 
VirtualComponentLifecycle.LIFECYCLE, VirtualComponentLifecycle.ATTACH, new 
Object[]{
+                    
TemplateDom.findAllComponentRefs(context.templateList.getRef(),context.position,
 component)
+            });
+        }
+     }
 
 
     /**
diff --git 
a/android/sdk/src/main/java/com/taobao/weex/ui/component/list/template/Selector.java
 
b/android/sdk/src/main/java/com/taobao/weex/ui/component/list/template/Selector.java
new file mode 100644
index 0000000000..3765c811eb
--- /dev/null
+++ 
b/android/sdk/src/main/java/com/taobao/weex/ui/component/list/template/Selector.java
@@ -0,0 +1,120 @@
+/**
+ * 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.template;
+
+import android.text.TextUtils;
+
+import com.taobao.weex.bridge.JSCallback;
+import com.taobao.weex.ui.component.WXComponent;
+import com.taobao.weex.ui.component.WXVContainer;
+import com.taobao.weex.ui.component.list.WXCell;
+
+import java.util.List;
+
+/**
+ * Created by furture on 2018/7/24.
+ */
+
+public class Selector {
+
+    /**
+     * @param  selector  [att=xx]
+     * query elements match selector, current only support attr selector
+     * */
+    public static void queryElementAll(WXComponent component, String selector, 
List<WXComponent> componentList){
+        if(TextUtils.isEmpty(selector)){
+            return;
+        }
+        selector = selector.replaceAll("\\[|]", "");
+        String[] args = selector.split("=");
+        if(args.length <= 0){
+            return;
+        }
+        String key = args[0];
+        String value = null;
+        if(args.length > 1){
+            value = args[1].trim();
+        }
+        if(component instanceof WXVContainer){
+            WXVContainer container = (WXVContainer) component;
+            for(int i=0; i<container.getChildCount(); i++){
+                queryElementAllByAttrs(container.getChild(i), key, value, 
componentList);
+            }
+        }
+    }
+
+
+    public static void closest(WXComponent component, String 
selector,List<WXComponent> componentList){
+        if(TextUtils.isEmpty(selector)){
+            return;
+        }
+        selector = selector.replaceAll("\\[|]", "");
+        String[] args = selector.split("=");
+        if(args.length <= 0){
+            return;
+        }
+        String key = args[0];
+        String value = null;
+        if(args.length > 1){
+            value = args[1].trim();
+        }
+        closestByAttrs(component, key, value, componentList);
+    }
+
+    private static void closestByAttrs(WXComponent component, String key, 
String value, List<WXComponent> componentList){
+        if(matchAttrs(component, key, value)){
+            componentList.add(component);
+        }
+        if(component instanceof  WXCell || component instanceof  
WXRecyclerTemplateList){
+            return;
+        }
+        queryElementAllByAttrs(component.getParent(), key, value, 
componentList);
+    }
+
+
+    private static void queryElementAllByAttrs(WXComponent component, String 
key, String value, List<WXComponent> componentList){
+        if(matchAttrs(component, key, value)){
+            componentList.add(component);
+        }
+        if(component instanceof WXVContainer){
+            WXVContainer container = (WXVContainer) component;
+            for(int i=0; i<container.getChildCount(); i++){
+                queryElementAllByAttrs(container.getChild(i), key, value, 
componentList);
+            }
+        }
+    }
+
+
+    private static boolean matchAttrs(WXComponent component, String key, 
String value){
+        if(component.isWaste()){
+            return false;
+        }
+        if(!component.getAttrs().containsKey(key)){
+            return false;
+        }
+        if(TextUtils.isEmpty(value)){
+            return true;
+        }
+        Object attrValue = component.getAttrs().get(key);
+        if(attrValue == null){
+            return false;
+        }
+        return value.equals(attrValue.toString());
+    }
+}
diff --git 
a/android/sdk/src/main/java/com/taobao/weex/ui/component/list/template/TemplateDom.java
 
b/android/sdk/src/main/java/com/taobao/weex/ui/component/list/template/TemplateDom.java
new file mode 100644
index 0000000000..78f7d90a5b
--- /dev/null
+++ 
b/android/sdk/src/main/java/com/taobao/weex/ui/component/list/template/TemplateDom.java
@@ -0,0 +1,226 @@
+/**
+ * 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.template;
+
+import android.support.v4.view.ViewCompat;
+import android.view.View;
+
+import com.taobao.weex.WXSDKManager;
+import com.taobao.weex.dom.WXAttr;
+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.WXRecyclerView;
+
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+
+/**
+ * Created by furture on 2018/6/27.
+ */
+
+public class TemplateDom {
+
+    public static final String KEY_RESET_ANIMATION = "resetAnimation";
+    public static final String KEY_ATTRS = "attrs";
+    public static final String KEY_TYPE = "type";
+    public static final String KEY_VIRTUAL_DOM_REF = "ref";
+    public static final String VIRTUAL_DOM_IDENTIFY = "[[VirtualElement]]";
+
+
+    public static final String ATTRS_KEY_REF = "ref";
+
+    public static final String ATTACH_CELL_SLOT = "_attach_slot";
+    public static final String DETACH_CELL_SLOT = "_detach_slot";
+
+    public static final char SEPARATOR = '@';
+
+
+    public static String genKeyVirtualDomRef(String listRef, int position, 
String key){
+        return listRef + SEPARATOR + position + SEPARATOR  +  key;
+    }
+
+    public static WXComponent findVirtualComponentByVRef(String pageId, String 
virtualRef) {
+        try{
+
+            String[]  segments = virtualRef.split(SEPARATOR + "");
+            String listRef = segments[0]; // list ref
+            WXComponent component = 
WXSDKManager.getInstance().getWXRenderManager().getWXComponent(pageId, listRef);
+            if(!(component instanceof WXRecyclerTemplateList)){
+                return null;
+            }
+            WXRecyclerTemplateList templateList = (WXRecyclerTemplateList) 
component;
+            if(templateList.getHostView() == null || 
templateList.getHostView().getInnerView() == null){
+                return null;
+            }
+            int position = Integer.parseInt(segments[1]); // position
+            WXRecyclerView recyclerView = 
templateList.getHostView().getInnerView();
+            TemplateViewHolder itemHolder = (TemplateViewHolder) 
recyclerView.findViewHolderForAdapterPosition(position);
+            if(itemHolder == null){
+                return null;
+            }
+
+            WXCell cell = itemHolder.getTemplate();
+            String viewKey = segments[2]; //viewkey
+            WXComponent target = findComponentByViewTreeKey(cell, viewKey);
+            return  target;
+        }catch (Exception e){
+            return  null;
+        }
+    }
+
+    /**
+     * find all component that contains ref attr
+     * */
+    public static Map<String,Object> findAllComponentRefs(String listRef, int 
position , WXComponent component){
+        Map<String,Object> refs = new HashMap<>();
+        findAllComponentRefs(listRef, position, component, refs);
+        Map<String,Object> refsMap = new HashMap<>();
+        refsMap.put("refs", refs);
+        refsMap.put("position", position);
+        refsMap.put("listRef", listRef);
+        return refsMap;
+    }
+
+    private static void findAllComponentRefs(String listRef, int position, 
WXComponent component, Map<String,Object> refs){
+        if(component.isWaste()){
+            return;
+        }
+        if(component instanceof WXVContainer){
+            WXVContainer container = (WXVContainer) component;
+            for(int i=0; i<container.getChildCount(); i++){
+                WXComponent child = container.getChild(i);
+                findAllComponentRefs(listRef, position, child, refs);
+            }
+        }
+        WXAttr attrs = component.getAttrs();
+        if(attrs != null
+                && attrs.get(TemplateDom.ATTRS_KEY_REF) == null){
+            return;
+        }
+        String ref  = attrs.get(TemplateDom.ATTRS_KEY_REF).toString();
+        List<Object> refList = (List<Object>) refs.get(ref);
+        if(refList == null){
+            refList = new ArrayList<>();
+            refs.put(ref, refList);
+        }
+        Map map = toMap(listRef, position, component);
+        refList.add(map);
+    }
+
+
+    public static Map toMap(String listRef, int position, WXComponent 
component){
+        Map map = new HashMap();
+        map.put(TemplateDom.KEY_ATTRS, component.getAttrs());
+        map.put(TemplateDom.KEY_TYPE, component.getComponentType());
+        map.put(TemplateDom.KEY_VIRTUAL_DOM_REF, 
TemplateDom.genKeyVirtualDomRef(listRef, position, component.getViewTreeKey()));
+        map.put(VIRTUAL_DOM_IDENTIFY, true);
+        return map;
+    }
+
+
+    public static boolean isVirtualDomRef(String ref){
+        if(ref != null){
+            return  ref.indexOf(SEPARATOR) > 0;
+        }
+        return  false;
+    }
+
+
+    public static void resetAnimaiton(View view){
+        if(view == null){
+            return;
+        }
+        if(ViewCompat.getTranslationX(view) != 0){
+            ViewCompat.setTranslationX(view, 0);
+        }
+
+        if(ViewCompat.getTranslationY(view) != 0){
+            ViewCompat.setTranslationY(view, 0);
+        }
+
+        if(ViewCompat.getTranslationZ(view) != 0){
+            ViewCompat.setTranslationZ(view, 0);
+        }
+
+        if(ViewCompat.getScaleX(view) != 1.0f){
+            ViewCompat.setScaleX(view, 1.0f);
+        }
+
+        if(ViewCompat.getScaleY(view) != 1.0f){
+            ViewCompat.setScaleY(view, 1.0f);
+        }
+
+        if(ViewCompat.getRotationX(view) != 0){
+            ViewCompat.setRotationX(view, 0);
+        }
+
+        if(ViewCompat.getRotationY(view) != 0){
+            ViewCompat.setRotationY(view, 0);
+        }
+
+        if(ViewCompat.getElevation(view) != 0){
+            ViewCompat.setElevation(view, 0);
+        }
+    }
+
+
+    /**
+     * find child list, has same ref
+     * */
+    public static final  WXComponent findComponentByViewTreeKey(WXComponent 
component, String viewKey){
+        if(component.getViewTreeKey().equals(viewKey)){
+            return component;
+        }
+        if(component instanceof WXVContainer){
+            WXVContainer container = (WXVContainer) component;
+            for(int i=0; i<container.getChildCount(); i++){
+                WXComponent element = container.getChild(i);
+                if(findComponentByViewTreeKey(element, viewKey) != null){
+                    return element;
+                }
+            }
+
+        }
+        return null;
+    }
+
+    /**
+     * find child by ref
+     * */
+    private  static WXComponent findChildByAttrsRef(WXComponent component, 
String ref){
+        if(component.getAttrs() != null && 
ref.equals(component.getAttrs().get(TemplateDom.ATTRS_KEY_REF))){
+            return component;
+        }
+        if(component instanceof WXVContainer){
+            WXVContainer container = (WXVContainer) component;
+            for(int i=0; i<container.getChildCount(); i++){
+                WXComponent child = findChildByAttrsRef(container.getChild(i), 
ref);
+                if(child != null){
+                    return  child;
+                }
+            }
+        }
+        return  null;
+    }
+
+
+}
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 70d135e98d..d6ed4157e2 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
@@ -42,8 +42,10 @@
 import com.alibaba.fastjson.JSONObject;
 import com.taobao.weex.WXEnvironment;
 import com.taobao.weex.WXSDKInstance;
+import com.taobao.weex.WXSDKManager;
 import com.taobao.weex.annotation.Component;
 import com.taobao.weex.annotation.JSMethod;
+import com.taobao.weex.bridge.JSCallback;
 import com.taobao.weex.common.Constants;
 import com.taobao.weex.common.ICheckBindingScroller;
 import com.taobao.weex.common.OnWXScrollListener;
@@ -97,7 +99,7 @@
     /**
      * trace log for template list
      * */
-    public static final boolean ENABLE_TRACE_LOG = true;
+    public static final boolean ENABLE_TRACE_LOG = false;
 
     public static final String TAG = "WXRecyclerTemplateList";
 
@@ -522,21 +524,129 @@ public void unbindDisappearEvent(WXComponent component) {
     }
 
 
-    @JSMethod
-    public void scrollTo(int position, Map<String, Object> options){
-        if (position >= 0) {
-            boolean smooth = true;
-            if(options != null) {
-                smooth = 
WXUtils.getBoolean(options.get(Constants.Name.ANIMATED), true);
+    @JSMethod(uiThread = true)
+    public void queryElement(String virtualRef, String selector, JSCallback 
callback){
+        try{
+            String[]  segments = virtualRef.split(TemplateDom.SEPARATOR + "");
+            String listRef = segments[0];
+            int position = Integer.parseInt(segments[1]); // position
+            WXComponent component = 
TemplateDom.findVirtualComponentByVRef(getInstanceId(), virtualRef);
+            if(component == null){
+                return;
             }
+            if(getHostView() == null || getHostView().getInnerView() == null){
+                return;
+            }
+            List<WXComponent>  componentList  = new ArrayList<>(4);
+            Selector.queryElementAll(component, selector, componentList);
+            if(componentList.size() > 0){
+                callback.invoke(TemplateDom.toMap(listRef, position, 
componentList.get(0)));
+            }else{
+                callback.invoke(new HashMap<>(4));
+            }
+        }catch (Exception e){
+            callback.invoke(new HashMap<>(4));
+            WXLogUtils.e(TAG, e);
+        }
+    }
 
-            final int pos = position;
-            BounceRecyclerView bounceRecyclerView = getHostView();
-            if (bounceRecyclerView == null) {
+    @JSMethod(uiThread = true)
+    public void queryElementAll(String virtualRef,  String selector, 
JSCallback callback){
+        List datas = new ArrayList();
+        try{
+            String[]  segments = virtualRef.split(TemplateDom.SEPARATOR + "");
+            String listRef = segments[0];
+            int position = Integer.parseInt(segments[1]); // position
+            WXComponent component = 
TemplateDom.findVirtualComponentByVRef(getInstanceId(), virtualRef);
+            if(component == null){
                 return;
             }
-            final WXRecyclerView view = bounceRecyclerView.getInnerView();
-            view.scrollTo(smooth, pos, 0, getOrientation());
+            if(getHostView() == null || getHostView().getInnerView() == null){
+                return;
+            }
+            List<WXComponent>  componentList  = new ArrayList<>(4);
+            Selector.queryElementAll(component, selector, componentList);
+            for(WXComponent child : componentList){
+                datas.add(TemplateDom.toMap(listRef, position, child));
+            }
+            callback.invoke(datas);
+        }catch (Exception e){
+            callback.invoke(datas);
+            WXLogUtils.e(TAG, e);
+        }
+    }
+
+    @JSMethod(uiThread = true)
+    public void closest(String virtualRef,  String selector, JSCallback 
callback){
+        try{
+            String[]  segments = virtualRef.split(TemplateDom.SEPARATOR + "");
+            String listRef = segments[0];
+            int position = Integer.parseInt(segments[1]); // position
+            WXComponent component = 
TemplateDom.findVirtualComponentByVRef(getInstanceId(), virtualRef);
+            if(component == null){
+                return;
+            }
+            if(getHostView() == null || getHostView().getInnerView() == null){
+                return;
+            }
+            List<WXComponent>  componentList  = new ArrayList<>(4);
+            Selector.closest(component, selector, componentList);
+            if(componentList.size() > 0){
+                callback.invoke(TemplateDom.toMap(listRef, position, 
componentList.get(0)));
+            }else{
+                callback.invoke(new HashMap<>(4));
+            }
+        }catch (Exception e){
+            callback.invoke(new HashMap<>(4));
+            WXLogUtils.e(TAG, e);
+        }
+    }
+
+
+
+    @JSMethod(uiThread = true)
+    public void scrollToElement(String virtualRef, Map<String, Object> 
options){
+        scrollTo(virtualRef, options);
+    }
+
+
+    @JSMethod(uiThread = true)
+    public void scrollTo(String virtualRef, Map<String, Object> options){
+        int position = -1;
+        try{
+            if(virtualRef.indexOf(TemplateDom.SEPARATOR) > 0){
+                String[]  segments = virtualRef.split(TemplateDom.SEPARATOR + 
"");
+                position = Integer.parseInt(segments[0]);
+            }else{
+                position = (int) Float.parseFloat(virtualRef);
+            }
+            if (position >= 0) {
+                boolean smooth = true;
+                float offsetFloat = 0;
+                if(options != null) {
+                    smooth = 
WXUtils.getBoolean(options.get(Constants.Name.ANIMATED), true);
+                    String offsetStr = options.get(Constants.Name.OFFSET) == 
null ? "0" : options.get(Constants.Name.OFFSET).toString();
+                    smooth = 
WXUtils.getBoolean(options.get(Constants.Name.ANIMATED), true);
+                    if (offsetStr != null) {
+                        try {
+                            offsetFloat = 
WXViewUtils.getRealPxByWidth(Float.parseFloat(offsetStr), 
getInstance().getInstanceViewPortWidth());
+                        }catch (Exception e ){
+                            WXLogUtils.e("Float parseFloat error 
:"+e.getMessage());
+                        }
+                    }
+                }
+                final int offset = (int) offsetFloat;
+
+                final int pos = position;
+                BounceRecyclerView bounceRecyclerView = getHostView();
+                if (bounceRecyclerView == null) {
+                    return;
+                }
+                final WXRecyclerView view = bounceRecyclerView.getInnerView();
+                view.scrollTo(smooth, pos, offset, getOrientation());
+            }
+        }catch (Exception e){
+            WXLogUtils.e(TAG, e);
         }
     }
 
@@ -1218,6 +1328,9 @@ public void onBindViewHolder(final TemplateViewHolder 
templateViewHolder, int po
         if(component == null){
             return;
         }
+        if(templateViewHolder.getHolderPosition() >= 0){
+            fireEvent(TemplateDom.DETACH_CELL_SLOT, 
TemplateDom.findAllComponentRefs(getRef(), position, component));
+        }
         long start = System.currentTimeMillis();
         templateViewHolder.setHolderPosition(position);
         Object data = cellDataManager.listData.get(position);
@@ -1227,6 +1340,7 @@ public void onBindViewHolder(final TemplateViewHolder 
templateViewHolder, int po
                 WXLogUtils.d(TAG,  position + " position "+ 
getTemplateKey(position) + " onBindViewHolder none data update "
                         + " component " + component.hashCode());
             }
+            fireEvent(TemplateDom.ATTACH_CELL_SLOT, 
TemplateDom.findAllComponentRefs(getRef(), position, component));
             return;  //none update just return
         }else{
             List<WXComponent> updates = doRenderTemplate(component, position);
@@ -1743,6 +1857,27 @@ public WXComponent findChildByRef(WXComponent component, 
String ref){
 
 
 
+    /**
+     * find child by ref
+     * */
+    public WXComponent findChildByAttrsRef(WXComponent component, String ref){
+        if(component.getAttrs() != null && 
ref.equals(component.getAttrs().get(TemplateDom.ATTRS_KEY_REF))){
+            return component;
+        }
+        if(component instanceof WXVContainer){
+            WXVContainer container = (WXVContainer) component;
+            for(int i=0; i<container.getChildCount(); i++){
+                WXComponent child = findChildByAttrsRef(container.getChild(i), 
ref);
+                if(child != null){
+                    return  child;
+                }
+            }
+        }
+        return  null;
+    }
+
+
+
     /**
      * @param  template  template name
      * get cell template component from cache, if cell component not load
diff --git 
a/android/sdk/src/main/java/com/taobao/weex/ui/view/gesture/WXGesture.java 
b/android/sdk/src/main/java/com/taobao/weex/ui/view/gesture/WXGesture.java
index ee48c6aeac..57f03f6b85 100644
--- a/android/sdk/src/main/java/com/taobao/weex/ui/view/gesture/WXGesture.java
+++ b/android/sdk/src/main/java/com/taobao/weex/ui/view/gesture/WXGesture.java
@@ -625,8 +625,14 @@ public boolean onDown(MotionEvent e) {
     return true;
   }
 
+  public boolean isRequestDisallowInterceptTouchEvent() {
+    return requestDisallowInterceptTouchEvent;
+  }
+
   public void setRequestDisallowInterceptTouchEvent(boolean 
requestDisallowInterceptTouchEvent) {
     this.requestDisallowInterceptTouchEvent = 
requestDisallowInterceptTouchEvent;
   }
 
+
+
 }


 

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
[email protected]


With regards,
Apache Git Services

Reply via email to