lifecycle manager
Project: http://git-wip-us.apache.org/repos/asf/incubator-weex/repo Commit: http://git-wip-us.apache.org/repos/asf/incubator-weex/commit/148135c4 Tree: http://git-wip-us.apache.org/repos/asf/incubator-weex/tree/148135c4 Diff: http://git-wip-us.apache.org/repos/asf/incubator-weex/diff/148135c4 Branch: refs/heads/0.16-dev Commit: 148135c4b3c51dfc06cd9e9315b045815e1c31a4 Parents: c4662c6 Author: jianbai.gbj <jianbai....@alibaba-inc.com> Authored: Tue Sep 19 17:29:55 2017 +0800 Committer: jianbai.gbj <jianbai....@alibaba-inc.com> Committed: Tue Sep 19 17:29:55 2017 +0800 ---------------------------------------------------------------------- .../java/com/taobao/weex/common/Constants.java | 12 +- .../list/template/CellLifecycleManager.java | 177 +++++++++++++++++ .../list/template/LifecycleManager.java | 188 ------------------- .../list/template/TemplateStickyHelper.java | 10 +- .../list/template/TemplateViewHolder.java | 8 +- .../list/template/WXRecyclerTemplateList.java | 75 ++++---- 6 files changed, 231 insertions(+), 239 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/incubator-weex/blob/148135c4/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 d5611d9..04d4387 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 @@ -191,7 +191,7 @@ public class Constants { String LIST_DATA_ITEM_ID = "itemId"; String CELL_INDEX = "cellIndex"; String TYPE_INDEX = "typeIndex"; - String APPEND = "append"; + String APPEND_LIST_DATA = "appendListData"; String UPDATE_CELL = "updateCell"; } @@ -282,11 +282,11 @@ public class Constants { String UNSTICKY = "unsticky"; String STICKY = "sticky"; - interface Recycler{ - String CREATE = "recycler-create"; - String ATTACH = "recycler-attach"; - String DETACH = "recycler-detach"; - String DESTORY = "recycler-destroy"; + interface SLOT_LIFECYCLE{ + String CREATE = "create"; + String ATTACH = "attach"; + String DETACH = "detach"; + String DESTORY = "destroy"; } } http://git-wip-us.apache.org/repos/asf/incubator-weex/blob/148135c4/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 new file mode 100644 index 0000000..2f54f9e --- /dev/null +++ b/android/sdk/src/main/java/com/taobao/weex/ui/component/list/template/CellLifecycleManager.java @@ -0,0 +1,177 @@ +/** + * 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.util.Log; + +import com.taobao.weex.common.Constants; +import com.taobao.weex.dom.WXEvent; +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.ArrayList; +import java.util.HashMap; +import java.util.List; +import java.util.Map; + +/** + * cell-slot lifecycle manager, onCreate onAttach onDetach destroy + * Created by furture on 2017/9/19. + */ +public class CellLifecycleManager { + + private static final String[] lifecycleEventNames = { + Constants.Event.SLOT_LIFECYCLE.CREATE, + Constants.Event.SLOT_LIFECYCLE.ATTACH, + Constants.Event.SLOT_LIFECYCLE.DETACH, + Constants.Event.SLOT_LIFECYCLE.DESTORY + }; + + private WXRecyclerTemplateList recyclerTemplateList; + private Map<String,Map<String,List<String>>> eventSlotWatchRefs; + private List<String> createEvent; // only call once + + + public CellLifecycleManager(WXRecyclerTemplateList recyclerTemplateList) { + this.recyclerTemplateList = recyclerTemplateList; + this.eventSlotWatchRefs = new HashMap<>(); + this.createEvent = new ArrayList<>(); + } + + + + public void updateSlotLifecycleWatch(WXCell cell, WXComponent component){ + WXEvent wxEvent = component.getDomObject().getEvents(); + for(String event : lifecycleEventNames){ + if(wxEvent.contains(event)){ + Map<String,List<String>> slotWatchRefs = eventSlotWatchRefs.get(event); + if(slotWatchRefs == null){ + slotWatchRefs = new HashMap<>(); + eventSlotWatchRefs.put(event, slotWatchRefs); + } + List<String> refs = slotWatchRefs.get(cell.getRef()); + if(refs == null){ + refs = new ArrayList<>(8); + slotWatchRefs.put(cell.getRef(), refs); + } + if(!refs.contains(component.getRef())){ + refs.add(component.getRef()); + } + } + } + if(component instanceof WXVContainer){ + WXVContainer container = (WXVContainer) component; + for(int i=0; i<container.getChildCount(); i++){ + WXComponent child = container.getChild(i); + updateSlotLifecycleWatch(cell, child); + } + } + } + + /** + * onCreate event + * */ + public void onCreate(int position){ + String key = recyclerTemplateList.getTemplateKey(position); + Map<String,List<String>> slotWatchCreateRefs = eventSlotWatchRefs.get(Constants.Event.SLOT_LIFECYCLE.CREATE); + if(slotWatchCreateRefs == null + || slotWatchCreateRefs.get(key) == null + || slotWatchCreateRefs.get(key).size() == 0){ + return; + } + if(createEvent.size() >= position){ + if(createEvent.contains(key + position)){ + return; + } + } + WXCell cell = recyclerTemplateList.getTemplates().get(key); + if(cell == null){ + return; + } + Map<String, Object> params = new HashMap<>(8); + params.put("position", position); + cell.fireEvent(Constants.Event.SLOT_LIFECYCLE.CREATE, params); + createEvent.add(key + position); + } + + + /** + * onAttach event + * */ + public void onAttach(int position, WXCell cell){ + if(cell == null || position < 0){ + return; + } + Map<String,List<String>> slotWatchAttachRefs = eventSlotWatchRefs.get(Constants.Event.SLOT_LIFECYCLE.ATTACH); + if(slotWatchAttachRefs == null + || slotWatchAttachRefs.get(cell.getRef()) == null + || slotWatchAttachRefs.get(cell.getRef()).size() == 0){ + return; + } + Map<String, Object> params = new HashMap<>(8); + params.put("position", position); + cell.fireEvent(Constants.Event.SLOT_LIFECYCLE.ATTACH, params); + } + + /** + * onDetach event + * */ + public void onDetach(int position, WXCell cell){ + if(cell == null || position < 0){ + return; + } + Map<String,List<String>> slotWatchDetachRefs = eventSlotWatchRefs.get(Constants.Event.SLOT_LIFECYCLE.ATTACH); + if(slotWatchDetachRefs == null + || slotWatchDetachRefs.get(cell.getRef()) == null + || slotWatchDetachRefs.get(cell.getRef()).size() == 0){ + return; + } + Map<String, Object> params = new HashMap<>(8); + params.put("position", position); + cell.fireEvent(Constants.Event.SLOT_LIFECYCLE.DETACH, params); + } + + /** + * onDestory event + * */ + public void onDestory(){ + Map<String,List<String>> slotWatchDestroyRefs = eventSlotWatchRefs.get(Constants.Event.SLOT_LIFECYCLE.DESTORY); + if(slotWatchDestroyRefs == null + || slotWatchDestroyRefs.size() == 0){ + return; + } + int size = recyclerTemplateList.getItemCount(); + for(int position=0; position<size; position++){ + String key = recyclerTemplateList.getTemplateKey(position); + if(slotWatchDestroyRefs.get(key) == null + || slotWatchDestroyRefs.get(key).size() == 0){ + return; + } + WXCell cell = recyclerTemplateList.getTemplates().get(key); + if(cell == null){ + return; + } + Map<String, Object> params = new HashMap<>(8); + params.put("position", position); + cell.fireEvent(Constants.Event.SLOT_LIFECYCLE.DESTORY, params); + } + eventSlotWatchRefs.clear(); + } +} http://git-wip-us.apache.org/repos/asf/incubator-weex/blob/148135c4/android/sdk/src/main/java/com/taobao/weex/ui/component/list/template/LifecycleManager.java ---------------------------------------------------------------------- diff --git a/android/sdk/src/main/java/com/taobao/weex/ui/component/list/template/LifecycleManager.java b/android/sdk/src/main/java/com/taobao/weex/ui/component/list/template/LifecycleManager.java deleted file mode 100644 index bfb3fed..0000000 --- a/android/sdk/src/main/java/com/taobao/weex/ui/component/list/template/LifecycleManager.java +++ /dev/null @@ -1,188 +0,0 @@ -/** - * 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.util.ArrayMap; - -import com.taobao.weex.common.Constants; -import com.taobao.weex.dom.WXEvent; -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.ArrayList; -import java.util.HashMap; -import java.util.List; -import java.util.Map; -import java.util.Set; - -/** - * cell-slot lifecycle manager - * Created by furture on 2017/9/19. - */ -public class LifecycleManager { - - private static final String[] eventNames = { - Constants.Event.Recycler.CREATE, - Constants.Event.Recycler.ATTACH, - Constants.Event.Recycler.DETACH, - Constants.Event.Recycler.DESTORY - }; - - - private WXRecyclerTemplateList recyclerTemplateList; - private Map<String,Map<String,List<String>>> eventSlotWatchRefs; - - - private Map<String,List<String>> slotWatchCreateRefs; - private Map<String,List<String>> slotWatchAttachRefs; - private Map<String,List<String>> slotWatchDetachRefs; - private Map<String,List<String>> slotWatchDestroyRefs; - private List<String> createEvent; - private Map<String, Object> params; - public LifecycleManager(WXRecyclerTemplateList recyclerTemplateList) { - this.recyclerTemplateList = recyclerTemplateList; - this.eventSlotWatchRefs = new HashMap<>(); - this.slotWatchCreateRefs = new ArrayMap<>(); - this.slotWatchAttachRefs = new ArrayMap<>(); - this.slotWatchDetachRefs = new ArrayMap<>(); - this.slotWatchDestroyRefs = new ArrayMap<>(); - this.createEvent = new ArrayList<>(); - this.params = new HashMap<>(); - } - - - - public void updateListData(){ - Map<String, WXCell> templates = recyclerTemplateList.getTemplates(); - Set<Map.Entry<String, WXCell>> entries = templates.entrySet(); - for(Map.Entry<String, WXCell> entry : entries){ - entry.getValue(); - } - } - - public void updateSlotLifecycle(WXCell cell, WXComponent component){ - WXEvent wxEvent = component.getDomObject().getEvents(); - for(String event : eventNames){ - if(wxEvent.contains(event)){ - Map<String,List<String>> slotWatchRefs = eventSlotWatchRefs.get(event); - if(slotWatchRefs == null){ - slotWatchRefs = new HashMap<>(); - eventSlotWatchRefs.put(event, slotWatchRefs); - } - List<String> refs = slotWatchRefs.get(cell.getRef()); - if(refs == null){ - refs = new ArrayList<>(8); - slotWatchRefs.put(cell.getRef(), refs); - } - if(refs.contains(component.getRef())){ - refs.add(component.getRef()); - } - } - } - if(component instanceof WXVContainer){ - WXVContainer container = (WXVContainer) component; - for(int k=0; k<container.getChildCount();){ - WXComponent next = container.getChild(k); - updateSlotLifecycle(cell, next); - } - } - } - - /** - * create event - * */ - public void create(int position){ - String key = recyclerTemplateList.getTemplateKey(position); - if(slotWatchCreateRefs.get(key) == null - || slotWatchCreateRefs.get(key).size() == 0){ - return; - } - if(createEvent.size() >= position){ - if(createEvent.contains(key + position)){ - return; - } - } - WXCell cell = recyclerTemplateList.getTemplates().get(key); - if(cell == null){ - return; - } - params.clear(); - params.put("position", position); - cell.fireEvent(Constants.Event.Recycler.CREATE, params); - createEvent.add(key + position); - } - - - /** - * attach event - * */ - public void attach(int position, WXCell cell){ - if(cell == null || position < 0){ - return; - } - if(slotWatchAttachRefs.get(cell.getRef()) == null - || slotWatchAttachRefs.get(cell.getRef()).size() == 0){ - return; - } - params.clear(); - params.put("position", position); - cell.fireEvent(Constants.Event.Recycler.ATTACH, params); - } - - /** - * detach event - * */ - public void detach(int position, WXCell cell){ - if(cell == null || position < 0){ - return; - } - if(slotWatchDetachRefs.get(cell.getRef()) == null - || slotWatchDetachRefs.get(cell.getRef()).size() == 0){ - return; - } - params.clear(); - params.put("position", position); - cell.fireEvent(Constants.Event.Recycler.DETACH, params); - } - - /** - * destory event - * */ - public void destory(){ - if(slotWatchDestroyRefs.size() == 0){ - return; - } - int size = recyclerTemplateList.getItemCount(); - for(int position=0; position<size; position++){ - String key = recyclerTemplateList.getTemplateKey(position); - if(slotWatchDestroyRefs.get(key) == null - || slotWatchDestroyRefs.get(key).size() == 0){ - return; - } - WXCell cell = recyclerTemplateList.getTemplates().get(key); - if(cell == null){ - return; - } - params.clear(); - params.put("position", position); - cell.fireEvent(Constants.Event.Recycler.DESTORY, params); - } - } -} http://git-wip-us.apache.org/repos/asf/incubator-weex/blob/148135c4/android/sdk/src/main/java/com/taobao/weex/ui/component/list/template/TemplateStickyHelper.java ---------------------------------------------------------------------- diff --git a/android/sdk/src/main/java/com/taobao/weex/ui/component/list/template/TemplateStickyHelper.java b/android/sdk/src/main/java/com/taobao/weex/ui/component/list/template/TemplateStickyHelper.java index 328276f..45c983b 100644 --- a/android/sdk/src/main/java/com/taobao/weex/ui/component/list/template/TemplateStickyHelper.java +++ b/android/sdk/src/main/java/com/taobao/weex/ui/component/list/template/TemplateStickyHelper.java @@ -39,12 +39,14 @@ public class TemplateStickyHelper { private WXRecyclerTemplateList recyclerTemplateList; private List<Integer> stickyPositions; private ArrayMap<Integer, TemplateViewHolder> stickyHolderCache; + private List<String> mStickyTypes; public TemplateStickyHelper(WXRecyclerTemplateList recyclerTemplateList) { this.recyclerTemplateList = recyclerTemplateList; this.stickyPositions = new ArrayList<>(); this.stickyHolderCache = new ArrayMap(); + this.mStickyTypes = new ArrayList<>(8); } /** @@ -120,7 +122,7 @@ public class TemplateStickyHelper { return; } - //create holder for match position if not exist + //onCreate holder for match position if not exist View stickyFakeView = bounceRecyclerView.getChildAt(bounceRecyclerView.getChildCount() - 1); if(!(stickyFakeView.getTag() instanceof TemplateViewHolder) || ((TemplateViewHolder) stickyFakeView.getTag()).getHolderPosition() != matchStickyPosition){ @@ -138,7 +140,7 @@ public class TemplateStickyHelper { } } - //create new sticky + //onCreate new sticky int stickyHolderType = recyclerTemplateList.getItemViewType(matchStickyPosition); TemplateViewHolder fakeStickyHolder = stickyHolderCache.get(stickyHolderType); if(fakeStickyHolder == null){ @@ -243,4 +245,8 @@ public class TemplateStickyHelper { } return stickyPositions; } + + public List<String> getStickyTypes() { + return mStickyTypes; + } } http://git-wip-us.apache.org/repos/asf/incubator-weex/blob/148135c4/android/sdk/src/main/java/com/taobao/weex/ui/component/list/template/TemplateViewHolder.java ---------------------------------------------------------------------- diff --git a/android/sdk/src/main/java/com/taobao/weex/ui/component/list/template/TemplateViewHolder.java b/android/sdk/src/main/java/com/taobao/weex/ui/component/list/template/TemplateViewHolder.java index 57f7b64..6a6c2b9 100644 --- a/android/sdk/src/main/java/com/taobao/weex/ui/component/list/template/TemplateViewHolder.java +++ b/android/sdk/src/main/java/com/taobao/weex/ui/component/list/template/TemplateViewHolder.java @@ -38,7 +38,7 @@ public class TemplateViewHolder extends ListBaseViewHolder { /** * strong reference, prevent recycled * */ - private WXComponent template; + private WXCell template; private CSSLayoutContext layoutContext; @@ -48,7 +48,7 @@ public class TemplateViewHolder extends ListBaseViewHolder { * header position * */ - public TemplateViewHolder(WXComponent component, int viewType) { + public TemplateViewHolder(WXCell component, int viewType) { super(component, viewType); this.template = component; } @@ -72,4 +72,8 @@ public class TemplateViewHolder extends ListBaseViewHolder { public void setHolderPosition(int holderPosition) { this.holderPosition = holderPosition; } + + public WXCell getTemplate() { + return template; + } } http://git-wip-us.apache.org/repos/asf/incubator-weex/blob/148135c4/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 52423e4..d219f61 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 @@ -141,7 +141,12 @@ public class WXRecyclerTemplateList extends WXVContainer<BounceRecyclerView> imp * sticky helper * */ private TemplateStickyHelper mStickyHelper; - private List<String> mStickyTypes; + + + /** + * cell item lifecycle manager + * */ + private CellLifecycleManager cellLifecycleManager; /** @@ -173,8 +178,8 @@ public class WXRecyclerTemplateList extends WXVContainer<BounceRecyclerView> imp mTemplateViewTypes.put("", 0); //empty view, when template was not sended mTemplates = new HashMap<>(); mStickyHelper = new TemplateStickyHelper(this); + cellLifecycleManager = new CellLifecycleManager(this); orientation = mDomObject.getOrientation(); - } @Override @@ -335,11 +340,8 @@ public class WXRecyclerTemplateList extends WXVContainer<BounceRecyclerView> imp if(listData == null || mStickyHelper == null){ return; } - if(mStickyTypes == null){ - mStickyTypes = new ArrayList<>(4); - } - if(!mStickyTypes.contains(template.getRef())){ - mStickyTypes.add(template.getRef()); + if(!mStickyHelper.getStickyTypes().contains(template.getRef())){ + mStickyHelper.getStickyTypes().add(template.getRef()); notifyUpdateList(); } } @@ -349,12 +351,11 @@ public class WXRecyclerTemplateList extends WXVContainer<BounceRecyclerView> imp WXComponent template = findParentType(component, WXCell.class); if(template == null || listData == null - || mStickyHelper == null - || mStickyTypes == null){ + || mStickyHelper == null){ return; } - if(mStickyTypes.contains(template.getRef())){ - mStickyTypes.remove(template.getRef()); + if(mStickyHelper.getStickyTypes().contains(template.getRef())){ + mStickyHelper.getStickyTypes().remove(template.getRef()); notifyUpdateList(); } } @@ -546,10 +547,13 @@ public class WXRecyclerTemplateList extends WXVContainer<BounceRecyclerView> imp } } } + cellLifecycleManager.updateSlotLifecycleWatch((WXCell)child, child); notifyUpdateList(); } } + + /** * RecyclerView manage its children in a way that different from {@link WXVContainer}. Therefore, * {@link WXVContainer#addSubView(View, int)} is an empty implementation in {@link @@ -560,8 +564,9 @@ public class WXRecyclerTemplateList extends WXVContainer<BounceRecyclerView> imp } + /** - * all child is template, none need create child except loading and refresh. + * all child is template, none need onCreate child except loading and refresh. * */ @Override public void createChildViewAt(int index) { @@ -578,30 +583,11 @@ public class WXRecyclerTemplateList extends WXVContainer<BounceRecyclerView> imp setRefreshOrLoading(child); } } + @Override public void remove(WXComponent child, boolean destroy) { removeFooterOrHeader(child); super.remove(child, destroy); - - /** - * T view = getHostView(); - 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); - } - * - * */ } @@ -634,8 +620,8 @@ public class WXRecyclerTemplateList extends WXVContainer<BounceRecyclerView> imp setListData(param); } return true; - case Constants.Name.Recycler.APPEND:{ - append(param); + case Constants.Name.Recycler.APPEND_LIST_DATA:{ + appendListData(param); } return true; case Constants.Name.Recycler.UPDATE_CELL:{ @@ -764,15 +750,14 @@ public class WXRecyclerTemplateList extends WXVContainer<BounceRecyclerView> imp inner.setScrollable(scrollable); } - @WXComponentProp(name = Constants.Name.Recycler.APPEND) - public void append(Object arrayObject){ + @WXComponentProp(name = Constants.Name.Recycler.APPEND_LIST_DATA) + public void appendListData(Object arrayObject){ if(listData == null){ listData = new JSONArray(); } if(arrayObject instanceof JSONObject){ listData.add(arrayObject); - } - if(arrayObject instanceof JSONArray){ + }else if(arrayObject instanceof JSONArray){ listData.addAll((JSONArray)arrayObject); } notifyUpdateList(); @@ -967,6 +952,7 @@ public class WXRecyclerTemplateList extends WXVContainer<BounceRecyclerView> imp @Override public void destroy() { + cellLifecycleManager.onDestory(); if(getHostView() != null){ getHostView().removeCallbacks(listUpdateRunnable); } @@ -1002,10 +988,11 @@ public class WXRecyclerTemplateList extends WXVContainer<BounceRecyclerView> imp if(templateViewHolder == null){ return; } - WXComponent component = templateViewHolder.getComponent(); + WXCell component = templateViewHolder.getTemplate(); if(component == null){ return; } + cellLifecycleManager.onDetach(templateViewHolder.getHolderPosition(), component); long start = System.currentTimeMillis(); templateViewHolder.setHolderPosition(position); Statements.doRender(component, getStackContextForPosition(position)); @@ -1013,8 +1000,9 @@ public class WXRecyclerTemplateList extends WXVContainer<BounceRecyclerView> imp WXLogUtils.d(TAG, position + getTemplateKey(position) + " onBindViewHolder render used " + (System.currentTimeMillis() - start)); } Layouts.doLayout(component, templateViewHolder.getLayoutContext()); + cellLifecycleManager.onAttach(position, component); if(WXEnvironment.isApkDebugable()){ - WXLogUtils.d(TAG, position + getTemplateKey(position) + " onBindViewHolder render used " + (System.currentTimeMillis() - start)); + WXLogUtils.d(TAG, position + getTemplateKey(position) + " onBindViewHolder layout used " + (System.currentTimeMillis() - start)); } } @@ -1146,6 +1134,9 @@ public class WXRecyclerTemplateList extends WXVContainer<BounceRecyclerView> imp if(mTemplateViewTypes == null || mTemplateViewTypes.size() <= 1){ return 0; } + if(mTemplates == null || mTemplates.size() == 0){ + return 0; + } return listData.size(); } @@ -1327,7 +1318,9 @@ public class WXRecyclerTemplateList extends WXVContainer<BounceRecyclerView> imp } private void notifyUpdateList(){ - if(getHostView() != null){ + if(getHostView() != null + && listUpdateRunnable != null + && getHostView().getInnerView() != null){ getHostView().removeCallbacks(listUpdateRunnable); getHostView().post(listUpdateRunnable); }