çå½å¨æçäºä»¶å®å
Project: http://git-wip-us.apache.org/repos/asf/incubator-weex/repo Commit: http://git-wip-us.apache.org/repos/asf/incubator-weex/commit/c8bed7ea Tree: http://git-wip-us.apache.org/repos/asf/incubator-weex/tree/c8bed7ea Diff: http://git-wip-us.apache.org/repos/asf/incubator-weex/diff/c8bed7ea Branch: refs/heads/0.16-dev Commit: c8bed7eae213b589c488a9bd0edabdccc76847aa Parents: 699da8f Author: jianbai.gbj <jianbai....@alibaba-inc.com> Authored: Wed Sep 20 21:41:17 2017 +0800 Committer: jianbai.gbj <jianbai....@alibaba-inc.com> Committed: Wed Sep 20 21:41:17 2017 +0800 ---------------------------------------------------------------------- .../list/template/CellLifecycleManager.java | 62 +++++++++++--------- .../list/template/WXRecyclerTemplateList.java | 25 ++++---- 2 files changed, 45 insertions(+), 42 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/incubator-weex/blob/c8bed7ea/android/sdk/src/main/java/com/taobao/weex/ui/component/list/template/CellLifecycleManager.java ---------------------------------------------------------------------- diff --git a/android/sdk/src/main/java/com/taobao/weex/ui/component/list/template/CellLifecycleManager.java b/android/sdk/src/main/java/com/taobao/weex/ui/component/list/template/CellLifecycleManager.java index 80880c2..054bb7a 100644 --- a/android/sdk/src/main/java/com/taobao/weex/ui/component/list/template/CellLifecycleManager.java +++ b/android/sdk/src/main/java/com/taobao/weex/ui/component/list/template/CellLifecycleManager.java @@ -18,8 +18,6 @@ */ package com.taobao.weex.ui.component.list.template; -import android.util.Log; - import com.taobao.weex.common.Constants; import com.taobao.weex.dom.WXEvent; import com.taobao.weex.ui.component.WXComponent; @@ -46,18 +44,18 @@ public class CellLifecycleManager { private WXRecyclerTemplateList recyclerTemplateList; private Map<String,Map<String,List<String>>> eventSlotWatchRefs; - private List<String> createEvent; // only call once + private Map<Integer,String> firedCreateEvent; // only call once public CellLifecycleManager(WXRecyclerTemplateList recyclerTemplateList) { this.recyclerTemplateList = recyclerTemplateList; this.eventSlotWatchRefs = new HashMap<>(); - this.createEvent = new ArrayList<>(); + this.firedCreateEvent = new HashMap<>(); } - public void updateSlotLifecycleWatch(WXCell cell, WXComponent component){ + public void filterLifecycleWatchEvent(WXCell cell, WXComponent component){ WXEvent wxEvent = component.getDomObject().getEvents(); for(String event : lifecycleEventNames){ if(wxEvent.contains(event)){ @@ -80,7 +78,7 @@ public class CellLifecycleManager { WXVContainer container = (WXVContainer) component; for(int i=0; i<container.getChildCount(); i++){ WXComponent child = container.getChild(i); - updateSlotLifecycleWatch(cell, child); + filterLifecycleWatchEvent(cell, child); } } } @@ -89,26 +87,25 @@ public class CellLifecycleManager { * onCreate event * */ public void onCreate(int position){ - String key = recyclerTemplateList.getTemplateKey(position); + WXCell cell = recyclerTemplateList.getSourceTemplate(position); + if(cell == null){ + return; + } Map<String,List<String>> slotWatchCreateRefs = eventSlotWatchRefs.get(Constants.Event.SLOT_LIFECYCLE.CREATE); if(slotWatchCreateRefs == null - || slotWatchCreateRefs.get(key) == null - || slotWatchCreateRefs.get(key).size() == 0){ + || slotWatchCreateRefs.get(cell.getRef()) == null + || slotWatchCreateRefs.get(cell.getRef()).size() == 0){ return; } - if(createEvent.size() >= position){ - if(createEvent.contains(key + position)){ - return; - } + if(cell.getRef().equals(firedCreateEvent.get(position))){ + return; } - WXCell cell = recyclerTemplateList.getTemplates().get(key); - if(cell == null){ + List<String> refs = slotWatchCreateRefs.get(cell.getRef()); + if(refs == null || refs.size() == 0){ return; } - Map<String, Object> params = new HashMap<>(8); - params.put("position", position); - cell.fireEvent(Constants.Event.SLOT_LIFECYCLE.CREATE, params); - createEvent.add(key + position); + fireChildEvent(Constants.Event.SLOT_LIFECYCLE.CREATE, cell, refs, position); + firedCreateEvent.put(position, cell.getRef()); } @@ -160,28 +157,35 @@ public class CellLifecycleManager { String key = recyclerTemplateList.getTemplateKey(position); if(slotWatchDestroyRefs.get(key) == null || slotWatchDestroyRefs.get(key).size() == 0){ - return; + continue; } WXCell cell = recyclerTemplateList.getTemplates().get(key); if(cell == null){ - return; + continue; + } + List<String> refs = slotWatchDestroyRefs.get(cell.getRef()); + if(refs == null || refs.size() == 0){ + continue; } - Map<String, Object> params = new HashMap<>(8); - params.put("position", position); - cell.fireEvent(Constants.Event.SLOT_LIFECYCLE.DESTORY, params); + fireChildEvent(Constants.Event.SLOT_LIFECYCLE.DESTORY, cell, refs, position); } eventSlotWatchRefs.clear(); } private final void fireChildEvent(String event, WXCell cell, List<String> refs, int position){ + if(refs == null || refs.size() == 0){ + return; + } for(String ref : refs){ - WXComponent component = recyclerTemplateList.findChildByRef(cell, ref); - if(component == null){ + List<WXComponent> components = recyclerTemplateList.findChildListByRef(cell, ref); + if(components == null || components.size() == 0){ continue; } - Map<String, Object> params = new HashMap<>(8); - params.put("position", position); - component.fireEvent(event, params); + for(WXComponent component : components) { + Map<String, Object> params = new HashMap<>(8); + params.put("position", position); + component.fireEvent(event, params); + } } } } http://git-wip-us.apache.org/repos/asf/incubator-weex/blob/c8bed7ea/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 d219f61..734e31d 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 @@ -283,7 +283,7 @@ public class WXRecyclerTemplateList extends WXVContainer<BounceRecyclerView> imp } } } - notifyWatchCreateEvent(); + fireOnCellOnCreateEvent(); if(getHostView() != null && getHostView().getRecyclerViewBaseAdapter() != null){ getHostView().getRecyclerViewBaseAdapter().notifyDataSetChanged(); } @@ -292,18 +292,8 @@ public class WXRecyclerTemplateList extends WXVContainer<BounceRecyclerView> imp return bounceRecyclerView; } - /** - * notify watch event - * */ - private void notifyWatchCreateEvent() { - if(listData != null){ - return; - } - - } - @Override protected void onHostViewInitialized(BounceRecyclerView host) { @@ -547,7 +537,7 @@ public class WXRecyclerTemplateList extends WXVContainer<BounceRecyclerView> imp } } } - cellLifecycleManager.updateSlotLifecycleWatch((WXCell)child, child); + cellLifecycleManager.filterLifecycleWatchEvent((WXCell)child, child); notifyUpdateList(); } } @@ -688,6 +678,15 @@ public class WXRecyclerTemplateList extends WXVContainer<BounceRecyclerView> imp if(update){ notifyUpdateList(); } + fireOnCellOnCreateEvent(); + } + + private void fireOnCellOnCreateEvent(){ + if(listData != null){ + for(int i=0; i<listData.size(); i++){ + cellLifecycleManager.onCreate(i); + } + } } @WXComponentProp(name = Constants.Name.OFFSET_ACCURACY) @@ -1097,7 +1096,7 @@ public class WXRecyclerTemplateList extends WXVContainer<BounceRecyclerView> imp /** * get source template * */ - private WXCell getSourceTemplate(int position){ + public WXCell getSourceTemplate(int position){ String template = getTemplateKey(position); return mTemplates.get(template); }