Skip to content

Commit 66571ad

Browse files
jianbai.gbjYorkShen
authored andcommitted
[WEEX-502][Android]Weex Template List Support Animation & queryElement & scrollToElement
1 parent c223f0d commit 66571ad

File tree

11 files changed

+547
-28
lines changed

11 files changed

+547
-28
lines changed

android/sdk/src/main/java/com/taobao/weex/ui/action/GraphicActionAnimation.java

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@
4747
import com.taobao.weex.ui.animation.WXAnimationModule;
4848
import com.taobao.weex.ui.animation.WidthProperty;
4949
import com.taobao.weex.ui.component.WXComponent;
50+
import com.taobao.weex.ui.component.list.template.TemplateDom;
5051
import com.taobao.weex.ui.view.border.BorderDrawable;
5152
import com.taobao.weex.utils.SingleFunctionParser;
5253
import com.taobao.weex.utils.WXLogUtils;
@@ -103,7 +104,13 @@ public void executeAction() {
103104

104105
WXComponent component = WXSDKManager.getInstance().getWXRenderManager().getWXComponent(getPageId(), getRef());
105106
if (component == null) {
106-
return;
107+
if(!TemplateDom.isVirtualDomRef(getRef())){
108+
return;
109+
}
110+
component = TemplateDom.findVirtualComponentByVRef(getPageId(), getRef());
111+
if(component == null){
112+
return;
113+
}
107114
}
108115

109116
WXSDKInstance instance = WXSDKManager.getInstance().getWXRenderManager().getWXSDKInstance(getPageId());
@@ -122,6 +129,8 @@ public void executeAction() {
122129
}
123130
}
124131

132+
133+
125134
private void startAnimation(@NonNull WXSDKInstance instance, @Nullable WXComponent component) {
126135
if (component != null) {
127136
if (mAnimationBean != null) {
@@ -270,5 +279,4 @@ public Float map(String raw) {
270279
}
271280
return null;
272281
}
273-
274282
}

android/sdk/src/main/java/com/taobao/weex/ui/animation/WXAnimationModule.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727
import com.taobao.weex.common.WXModule;
2828
import com.taobao.weex.ui.action.GraphicActionAnimation;
2929
import com.taobao.weex.ui.component.WXComponent;
30+
import com.taobao.weex.ui.component.list.template.TemplateDom;
3031

3132
public class WXAnimationModule extends WXModule {
3233

@@ -40,6 +41,9 @@ public void transition(@Nullable String ref, @Nullable String animation, @Nullab
4041
}
4142
}
4243

44+
45+
46+
4347
//add by moxun on 12/26/2016
4448
public static class AnimationHolder {
4549

android/sdk/src/main/java/com/taobao/weex/ui/component/WXComponent.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -517,7 +517,7 @@ public void onCallback(Object result) {
517517
};
518518
try{
519519
fireEvent(type, params, null, callback);
520-
waitLatch.await(10, TimeUnit.MILLISECONDS);
520+
waitLatch.await(50, TimeUnit.MILLISECONDS);
521521
return callback;
522522
}catch (Exception e){
523523
if(WXEnvironment.isApkDebugable()){

android/sdk/src/main/java/com/taobao/weex/ui/component/WXVContainer.java

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,6 @@ public abstract class WXVContainer<T extends ViewGroup> extends WXComponent<T> {
4646
private static final String TAG = "WXVContainer";
4747
protected ArrayList<WXComponent> mChildren = new ArrayList<>();
4848
private BoxShadowHost mBoxShadowHost;
49-
private boolean requestDisallowInterceptTouchEvent = false;
5049

5150
@Deprecated
5251
public WXVContainer(WXSDKInstance instance, WXVContainer parent, String instanceId, boolean isLazy, BasicComponentData basicComponentData) {
@@ -541,14 +540,14 @@ private void doViewTreeRecycleImageView(ViewGroup viewGroup, boolean isRelease){
541540

542541

543542
public void requestDisallowInterceptTouchEvent(boolean requestDisallowInterceptTouchEvent) {
544-
if(this.requestDisallowInterceptTouchEvent != requestDisallowInterceptTouchEvent){
545-
this.requestDisallowInterceptTouchEvent = requestDisallowInterceptTouchEvent;
546-
if(mGesture != null){
547-
mGesture.setRequestDisallowInterceptTouchEvent(requestDisallowInterceptTouchEvent);
548-
}
549-
if(getParent() != null){
550-
getParent().requestDisallowInterceptTouchEvent(requestDisallowInterceptTouchEvent);
543+
if(mGesture != null){
544+
if(mGesture.isRequestDisallowInterceptTouchEvent()){
545+
return;
551546
}
547+
mGesture.setRequestDisallowInterceptTouchEvent(requestDisallowInterceptTouchEvent);
548+
}
549+
if(getParent() != null){
550+
getParent().requestDisallowInterceptTouchEvent(requestDisallowInterceptTouchEvent);
552551
}
553552
}
554553

android/sdk/src/main/java/com/taobao/weex/ui/component/binding/AsynLayoutTask.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
import android.os.AsyncTask;
2222

2323
import com.taobao.weex.ui.component.WXComponent;
24+
import com.taobao.weex.ui.component.list.template.TemplateDom;
2425
import com.taobao.weex.ui.component.list.template.TemplateViewHolder;
2526

2627
/**
@@ -54,6 +55,9 @@ protected void onPostExecute(Void aVoid) {
5455
if(position == templateViewHolder.getHolderPosition()) {
5556
if(component.getInstance() != null && !component.getInstance().isDestroy()) {
5657
Layouts.setLayout(component, false);
58+
if(templateViewHolder.getHolderPosition() >= 0){
59+
templateViewHolder.getTemplateList().fireEvent("_attach_slot", TemplateDom.findAllComponentRefs(templateViewHolder.getTemplateList().getRef(), position, component));
60+
}
5761
}
5862
}
5963
}

android/sdk/src/main/java/com/taobao/weex/ui/component/binding/Layouts.java

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,10 +28,12 @@
2828
import com.taobao.weex.ui.component.WXComponent;
2929
import com.taobao.weex.ui.component.WXVContainer;
3030
import com.taobao.weex.ui.component.list.WXCell;
31+
import com.taobao.weex.ui.component.list.template.TemplateDom;
3132
import com.taobao.weex.ui.component.list.template.TemplateViewHolder;
3233
import com.taobao.weex.ui.component.list.template.WXRecyclerTemplateList;
3334
import com.taobao.weex.ui.component.list.template.jni.NativeRenderObjectUtils;
3435
import com.taobao.weex.utils.WXLogUtils;
36+
import com.taobao.weex.utils.WXUtils;
3537

3638
/**
3739
* Created by furture on 2017/8/21.
@@ -55,6 +57,9 @@ public static void doLayoutAsync(final TemplateViewHolder templateViewHolder, bo
5557
}else{
5658
doLayoutOnly(component, templateViewHolder);
5759
setLayout(component, false);
60+
if(templateViewHolder.getHolderPosition() >= 0){
61+
templateViewHolder.getTemplateList().fireEvent("_attach_slot", TemplateDom.findAllComponentRefs(templateViewHolder.getTemplateList().getRef(), position, component));
62+
}
5863
}
5964

6065
}
@@ -106,6 +111,11 @@ public static final void setLayout(WXComponent component, boolean force){
106111
if(component.isWaste()){
107112
return;
108113
}
114+
if(component.getAttrs().containsKey(TemplateDom.KEY_RESET_ANIMATION)){
115+
if(WXUtils.getBoolean(component.getAttrs().get(TemplateDom.KEY_RESET_ANIMATION), true).booleanValue()){
116+
TemplateDom.resetAnimaiton(component.getHostView());
117+
}
118+
}
109119
long ptr = component.getRenderObjectPtr();
110120
if(NativeRenderObjectUtils.nativeRenderObjectHasNewLayout(ptr)){
111121
NativeRenderObjectUtils.nativeRenderObjectUpdateComponent(ptr, component);

android/sdk/src/main/java/com/taobao/weex/ui/component/binding/Statements.java

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@
4747
import com.taobao.weex.ui.component.list.WXCell;
4848
import com.taobao.weex.ui.component.list.template.CellDataManager;
4949
import com.taobao.weex.ui.component.list.template.CellRenderContext;
50+
import com.taobao.weex.ui.component.list.template.TemplateDom;
5051
import com.taobao.weex.ui.component.list.template.VirtualComponentLifecycle;
5152
import com.taobao.weex.ui.component.list.template.WXRecyclerTemplateList;
5253
import com.taobao.weex.ui.component.list.template.jni.NativeRenderObjectUtils;
@@ -356,15 +357,16 @@ private static void doBindingAttrsEventAndRenderChildNode(WXComponent component,
356357
ArrayStack stack = context.stack;
357358

358359

359-
360+
String virtualComponentId = null;
361+
boolean callVirtualComponentAttach = false;
360362
if(attr.get(ELUtils.IS_COMPONENT_ROOT) != null
361363
&& WXUtils.getBoolean(attr.get(ELUtils.IS_COMPONENT_ROOT), false)){
362364
if(attr.get(ELUtils.COMPONENT_PROPS) != null
363365
&& JSONUtils.isJSON(attr.get(ELUtils.COMPONENT_PROPS))){
364366
String compoentId = (String) attr.get(CellDataManager.SUB_COMPONENT_TEMPLATE_ID);
365367
Object compoentData = null;
366368
if(!TextUtils.isEmpty(compoentId)){
367-
String virtualComponentId = context.getRenderState().getVirtualComponentIds().get(component.getViewTreeKey());
369+
virtualComponentId = context.getRenderState().getVirtualComponentIds().get(component.getViewTreeKey());
368370
if(virtualComponentId == null){ //none virtualComponentId, create and do attach
369371
virtualComponentId = CellDataManager.createVirtualComponentId(context.templateList.getRef(),
370372
component.getViewTreeKey(), context.templateList.getItemId(context.position));
@@ -381,8 +383,7 @@ private static void doBindingAttrsEventAndRenderChildNode(WXComponent component,
381383
compoentData = props;
382384
context.getRenderState().getVirtualComponentIds().put(component.getViewTreeKey(), virtualComponentId);
383385
context.templateList.getCellDataManager().createVirtualComponentData(context.position, virtualComponentId, compoentData);
384-
//create virtual componentId
385-
WXBridgeManager.getInstance().asyncCallJSEventVoidResult(WXBridgeManager.METHD_COMPONENT_HOOK_SYNC, component.getInstanceId(), null, virtualComponentId, VirtualComponentLifecycle.LIFECYCLE, VirtualComponentLifecycle.ATTACH, null);
386+
callVirtualComponentAttach = true; // when first create virtual compoent, call create
386387
}else{ // get virtual component data check has dirty's update
387388
compoentData = context.getRenderState().getVirtualComponentDatas().get(virtualComponentId);
388389
if(context.getRenderState().isHasDataUpdate()){
@@ -446,7 +447,13 @@ private static void doBindingAttrsEventAndRenderChildNode(WXComponent component,
446447
if(stack != context.stack){
447448
context.stack = stack;
448449
}
449-
}
450+
//create virtual componentId
451+
if(callVirtualComponentAttach && virtualComponentId != null){
452+
WXBridgeManager.getInstance().asyncCallJSEventVoidResult(WXBridgeManager.METHD_COMPONENT_HOOK_SYNC, component.getInstanceId(), null, virtualComponentId, VirtualComponentLifecycle.LIFECYCLE, VirtualComponentLifecycle.ATTACH, new Object[]{
453+
TemplateDom.findAllComponentRefs(context.templateList.getRef(),context.position, component)
454+
});
455+
}
456+
}
450457

451458

452459
/**
Lines changed: 120 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,120 @@
1+
/**
2+
* Licensed to the Apache Software Foundation (ASF) under one
3+
* or more contributor license agreements. See the NOTICE file
4+
* distributed with this work for additional information
5+
* regarding copyright ownership. The ASF licenses this file
6+
* to you under the Apache License, Version 2.0 (the
7+
* "License"); you may not use this file except in compliance
8+
* with the License. You may obtain a copy of the License at
9+
*
10+
* http://www.apache.org/licenses/LICENSE-2.0
11+
*
12+
* Unless required by applicable law or agreed to in writing,
13+
* software distributed under the License is distributed on an
14+
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15+
* KIND, either express or implied. See the License for the
16+
* specific language governing permissions and limitations
17+
* under the License.
18+
*/
19+
package com.taobao.weex.ui.component.list.template;
20+
21+
import android.text.TextUtils;
22+
23+
import com.taobao.weex.bridge.JSCallback;
24+
import com.taobao.weex.ui.component.WXComponent;
25+
import com.taobao.weex.ui.component.WXVContainer;
26+
import com.taobao.weex.ui.component.list.WXCell;
27+
28+
import java.util.List;
29+
30+
/**
31+
* Created by furture on 2018/7/24.
32+
*/
33+
34+
public class Selector {
35+
36+
/**
37+
* @param selector [att=xx]
38+
* query elements match selector, current only support attr selector
39+
* */
40+
public static void queryElementAll(WXComponent component, String selector, List<WXComponent> componentList){
41+
if(TextUtils.isEmpty(selector)){
42+
return;
43+
}
44+
selector = selector.replaceAll("\\[|]", "");
45+
String[] args = selector.split("=");
46+
if(args.length <= 0){
47+
return;
48+
}
49+
String key = args[0];
50+
String value = null;
51+
if(args.length > 1){
52+
value = args[1].trim();
53+
}
54+
if(component instanceof WXVContainer){
55+
WXVContainer container = (WXVContainer) component;
56+
for(int i=0; i<container.getChildCount(); i++){
57+
queryElementAllByAttrs(container.getChild(i), key, value, componentList);
58+
}
59+
}
60+
}
61+
62+
63+
public static void closest(WXComponent component, String selector,List<WXComponent> componentList){
64+
if(TextUtils.isEmpty(selector)){
65+
return;
66+
}
67+
selector = selector.replaceAll("\\[|]", "");
68+
String[] args = selector.split("=");
69+
if(args.length <= 0){
70+
return;
71+
}
72+
String key = args[0];
73+
String value = null;
74+
if(args.length > 1){
75+
value = args[1].trim();
76+
}
77+
closestByAttrs(component, key, value, componentList);
78+
}
79+
80+
private static void closestByAttrs(WXComponent component, String key, String value, List<WXComponent> componentList){
81+
if(matchAttrs(component, key, value)){
82+
componentList.add(component);
83+
}
84+
if(component instanceof WXCell || component instanceof WXRecyclerTemplateList){
85+
return;
86+
}
87+
queryElementAllByAttrs(component.getParent(), key, value, componentList);
88+
}
89+
90+
91+
private static void queryElementAllByAttrs(WXComponent component, String key, String value, List<WXComponent> componentList){
92+
if(matchAttrs(component, key, value)){
93+
componentList.add(component);
94+
}
95+
if(component instanceof WXVContainer){
96+
WXVContainer container = (WXVContainer) component;
97+
for(int i=0; i<container.getChildCount(); i++){
98+
queryElementAllByAttrs(container.getChild(i), key, value, componentList);
99+
}
100+
}
101+
}
102+
103+
104+
private static boolean matchAttrs(WXComponent component, String key, String value){
105+
if(component.isWaste()){
106+
return false;
107+
}
108+
if(!component.getAttrs().containsKey(key)){
109+
return false;
110+
}
111+
if(TextUtils.isEmpty(value)){
112+
return true;
113+
}
114+
Object attrValue = component.getAttrs().get(key);
115+
if(attrValue == null){
116+
return false;
117+
}
118+
return value.equals(attrValue.toString());
119+
}
120+
}

0 commit comments

Comments
 (0)