diff --git a/renderer/native/android/src/main/java/androidx/recyclerview/widget/HippyLinearLayoutManager.java b/renderer/native/android/src/main/java/androidx/recyclerview/widget/HippyLinearLayoutManager.java index 085bf5dd61a..d1c58c554af 100644 --- a/renderer/native/android/src/main/java/androidx/recyclerview/widget/HippyLinearLayoutManager.java +++ b/renderer/native/android/src/main/java/androidx/recyclerview/widget/HippyLinearLayoutManager.java @@ -127,11 +127,10 @@ int getSizeUntilPosition(int position) { if (size == null) { size = getItemSizeFromAdapter(i); } - if (size != null && size != INVALID_SIZE) { - totalSize += size; - } else { + if (size == INVALID_SIZE) { return INVALID_SIZE; } + totalSize += size; } return totalSize; } diff --git a/renderer/native/android/src/main/java/com/tencent/mtt/hippy/uimanager/RenderManager.java b/renderer/native/android/src/main/java/com/tencent/mtt/hippy/uimanager/RenderManager.java index c82d88444c6..85676097fd3 100644 --- a/renderer/native/android/src/main/java/com/tencent/mtt/hippy/uimanager/RenderManager.java +++ b/renderer/native/android/src/main/java/com/tencent/mtt/hippy/uimanager/RenderManager.java @@ -153,8 +153,7 @@ public void createNode(int rootId, int id, int pid, int index, "appendVirtualChild: rootNode=" + rootNode + " parentNode=" + parentNode); return; } - RenderNode node = mControllerManager.createRenderNode(rootId, id, props, className, - isLazy || parentNode.checkNodeFlag(FLAG_LAZY_LOAD)); + RenderNode node = mControllerManager.createRenderNode(rootId, id, props, className, isLazy); if (node == null) { LogUtils.w(TAG, "createNode: node == null"); return; diff --git a/renderer/native/android/src/main/java/com/tencent/mtt/hippy/views/hippylist/HippyRecyclerListAdapter.java b/renderer/native/android/src/main/java/com/tencent/mtt/hippy/views/hippylist/HippyRecyclerListAdapter.java index 8cde8d1ccc8..973fc728349 100644 --- a/renderer/native/android/src/main/java/com/tencent/mtt/hippy/views/hippylist/HippyRecyclerListAdapter.java +++ b/renderer/native/android/src/main/java/com/tencent/mtt/hippy/views/hippylist/HippyRecyclerListAdapter.java @@ -306,11 +306,7 @@ public int getRenderNodeTotalHeight() { } public int getItemHeight(int position) { - Integer itemHeight = getRenderNodeHeight(position); - if (itemHeight != null) { - return itemHeight; - } - return 0; + return getRenderNodeHeight(position); } public int getRenderNodeHeight(int position) { @@ -336,11 +332,7 @@ public int getRenderNodeHeight(int position) { } public int getItemWidth(int position) { - Integer renderNodeWidth = getRenderNodeWidth(position); - if (renderNodeWidth != null) { - return renderNodeWidth; - } - return 0; + return getRenderNodeWidth(position); } public int getRenderNodeWidth(int position) { @@ -406,6 +398,7 @@ public void getItemLayoutParams(int position, LayoutParams lp) { return; } lp.height = getItemHeight(position); + lp.width = getItemWidth(position); } /*package*/ boolean hasHeader() { diff --git a/renderer/native/android/src/main/java/com/tencent/mtt/hippy/views/hippylist/HippyRecyclerViewController.java b/renderer/native/android/src/main/java/com/tencent/mtt/hippy/views/hippylist/HippyRecyclerViewController.java index 5005a3dfecb..d922c379be4 100644 --- a/renderer/native/android/src/main/java/com/tencent/mtt/hippy/views/hippylist/HippyRecyclerViewController.java +++ b/renderer/native/android/src/main/java/com/tencent/mtt/hippy/views/hippylist/HippyRecyclerViewController.java @@ -35,6 +35,7 @@ import com.tencent.mtt.hippy.common.HippyMap; import com.tencent.mtt.hippy.dom.node.NodeProps; import com.tencent.mtt.hippy.uimanager.ControllerManager; +import com.tencent.mtt.hippy.uimanager.ControllerRegistry; import com.tencent.mtt.hippy.uimanager.HippyViewController; import com.tencent.renderer.NativeRenderContext; import com.tencent.renderer.node.ListViewRenderNode; @@ -144,6 +145,17 @@ public RenderNode createRenderNode(int rootId, int id, @Nullable Map) view).getRecyclerView().dispatchLayout(); + } + } + @HippyControllerProps(name = "horizontal", defaultType = HippyControllerProps.BOOLEAN) public void setHorizontalEnable(final HRW viewWrapper, boolean flag) { LayoutManager layoutManager = viewWrapper.getRecyclerView().getLayoutManager(); diff --git a/renderer/native/android/src/main/java/com/tencent/renderer/node/ListItemRenderNode.java b/renderer/native/android/src/main/java/com/tencent/renderer/node/ListItemRenderNode.java index 690943d35d8..a2d6dbf94a9 100644 --- a/renderer/native/android/src/main/java/com/tencent/renderer/node/ListItemRenderNode.java +++ b/renderer/native/android/src/main/java/com/tencent/renderer/node/ListItemRenderNode.java @@ -171,6 +171,7 @@ public void updateLayout(int x, int y, int w, int h) { mLeft = x; mTop = y; View view = mControllerManager.findView(mRootId, mId); + mX = view != null ? view.getLeft() : 0; mY = view != null ? view.getTop() : 0; if (getParent() != null) { RenderManager renderManager = mControllerManager.getRenderManager(); diff --git a/renderer/native/android/src/main/java/com/tencent/renderer/node/RenderNode.java b/renderer/native/android/src/main/java/com/tencent/renderer/node/RenderNode.java index 34ccdeab4a0..fb136787b72 100644 --- a/renderer/native/android/src/main/java/com/tencent/renderer/node/RenderNode.java +++ b/renderer/native/android/src/main/java/com/tencent/renderer/node/RenderNode.java @@ -91,6 +91,10 @@ public class RenderNode { * Mark should update children drawing order. */ public static final int FLAG_UPDATE_DRAWING_ORDER = 0x00000100; + /** + * Mark node has lazy parent node, which means there is an ancestor node has flag {@link #FLAG_LAZY_LOAD}. + */ + public static final int FLAG_PARENT_LAZY_LOAD = 0x00000200; private int mNodeFlags = 0; private PoolType mPoolInUse = PoolType.NONE; protected int mX; @@ -280,6 +284,7 @@ public void addChild(@NonNull RenderNode node, int index) { index = (index < 0) ? 0 : Math.min(index, mChildren.size()); mChildren.add(index, node); node.mParent = this; + node.onParentLazyChanged(isLazyLoad()); // If has set z index in the child nodes, the rendering order needs to be rearranged // after adding nodes if (mDrawingOrder != null) { @@ -288,15 +293,38 @@ public void addChild(@NonNull RenderNode node, int index) { } public void setLazy(boolean isLazy) { + if (isLazy == checkNodeFlag(FLAG_LAZY_LOAD)) { + return; + } + boolean oldLazy = isLazyLoad(); if (isLazy) { setNodeFlag(FLAG_LAZY_LOAD); } else { resetNodeFlag(FLAG_LAZY_LOAD); } - for (int i = 0; i < getChildCount(); i++) { - RenderNode child = getChildAt(i); - if (child != null) { - child.setLazy(isLazy); + notifyLazyChanged(oldLazy, isLazyLoad()); + } + + public void onParentLazyChanged(boolean isLazy) { + if (isLazy == checkNodeFlag(FLAG_PARENT_LAZY_LOAD)) { + return; + } + boolean oldLazy = isLazyLoad(); + if (isLazy) { + setNodeFlag(FLAG_PARENT_LAZY_LOAD); + } else { + resetNodeFlag(FLAG_PARENT_LAZY_LOAD); + } + notifyLazyChanged(oldLazy, isLazyLoad()); + } + + private void notifyLazyChanged(boolean oldLazy, boolean newLazy) { + if (oldLazy != newLazy) { + for (int i = 0; i < getChildCount(); i++) { + RenderNode child = getChildAt(i); + if (child != null) { + child.onParentLazyChanged(newLazy); + } } } } @@ -659,7 +687,7 @@ public boolean isDeleted() { } public boolean isLazyLoad() { - return checkNodeFlag(FLAG_LAZY_LOAD); + return checkNodeFlag(FLAG_LAZY_LOAD) || checkNodeFlag(FLAG_PARENT_LAZY_LOAD); } public boolean checkRegisteredEvent(@NonNull String eventName) {