Skip to content

Commit

Permalink
Merge branch 'main' into feature/update-vue-docs
Browse files Browse the repository at this point in the history
  • Loading branch information
open-hippy authored Dec 15, 2023
2 parents 6e81734 + 795aff4 commit 850993b
Show file tree
Hide file tree
Showing 6 changed files with 52 additions and 20 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand All @@ -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) {
Expand Down Expand Up @@ -406,6 +398,7 @@ public void getItemLayoutParams(int position, LayoutParams lp) {
return;
}
lp.height = getItemHeight(position);
lp.width = getItemWidth(position);
}

/*package*/ boolean hasHeader() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -144,6 +145,17 @@ public RenderNode createRenderNode(int rootId, int id, @Nullable Map<String, Obj
return new ListViewRenderNode(rootId, id, props, className, controllerManager, isLazyLoad);
}

@Override
public void updateLayout(int rootId, int id, int x, int y, int width, int height,
ControllerRegistry componentHolder) {
super.updateLayout(rootId, id, x, y, width, height, componentHolder);
// nested list may not receive onBatchComplete, so we have to call dispatchLayout here
View view = componentHolder.getView(rootId, id);
if (view instanceof HippyRecyclerViewWrapper) {
((HippyRecyclerViewWrapper<?>) view).getRecyclerView().dispatchLayout();
}
}

@HippyControllerProps(name = "horizontal", defaultType = HippyControllerProps.BOOLEAN)
public void setHorizontalEnable(final HRW viewWrapper, boolean flag) {
LayoutManager layoutManager = viewWrapper.getRecyclerView().getLayoutManager();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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) {
Expand All @@ -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);
}
}
}
}
Expand Down Expand Up @@ -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) {
Expand Down

0 comments on commit 850993b

Please sign in to comment.