Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix/delete virtual node #3990

Merged
merged 2 commits into from
Aug 12, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -178,8 +178,8 @@ public HippyCustomPropsController getCustomPropsController() {
}

public void destroy() {
mControllerRegistry.clear();
mControllerUpdateManger.clear();
mControllerRegistry.destroy();
mControllerUpdateManger.destroy();
for (Pool<Integer, View> pool : mPreCreateViewPools.values()) {
pool.clear();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,11 @@ public ControllerRegistry(@NonNull Renderer renderer) {
mRendererWeakRef = new WeakReference<>(renderer);
}

public void clear() {}
void destroy() {
mViews.clear();
mRootViews.clear();
mControllers.clear();
}

public void addControllerHolder(String name, ControllerHolder controllerHolder) {
mControllers.put(name, controllerHolder);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ public ControllerUpdateManger(@NonNull Renderer renderer) {
mRendererWeakRef = new WeakReference<>(renderer);
}

public void clear() {
void destroy() {

}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,10 @@

package com.tencent.mtt.hippy.uimanager;

import static com.tencent.mtt.hippy.dom.node.NodeProps.TEXT_CLASS_NAME;
import static com.tencent.renderer.NativeRenderer.NODE_ID;
import static com.tencent.renderer.NativeRenderer.NODE_INDEX;
import static com.tencent.renderer.node.RenderNode.FLAG_ALREADY_DELETED;
import static com.tencent.renderer.node.RenderNode.FLAG_LAZY_LOAD;
import static com.tencent.renderer.node.RenderNode.FLAG_UPDATE_TOTAL_PROPS;

import android.content.Context;
Expand All @@ -29,6 +29,7 @@
import androidx.annotation.NonNull;

import com.openhippy.pool.BasePool.PoolType;
import com.tencent.renderer.NativeRender;
import com.tencent.renderer.NativeRenderContext;
import com.tencent.renderer.NativeRendererManager;
import com.tencent.renderer.Renderer;
Expand All @@ -39,6 +40,7 @@
import com.tencent.renderer.node.TextRenderNode;
import com.tencent.renderer.node.RenderNode;

import java.lang.ref.WeakReference;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Comparator;
Expand Down Expand Up @@ -66,8 +68,11 @@ public class RenderManager {
private final ControllerManager mControllerManager;
@NonNull
private final Map<Integer, LinkedHashSet<RenderNode>> mUIUpdateNodes = new HashMap<>();
@Nullable
private final WeakReference<Renderer> mRendererWeakRef;

public RenderManager(Renderer renderer) {
mRendererWeakRef = new WeakReference<>(renderer);
mControllerManager = new ControllerManager(renderer);
}

Expand Down Expand Up @@ -381,6 +386,12 @@ private void deleteSelfFromParent(int rootId, @Nullable RenderNode node) {
node.getParent().removeChild(node);
}
removeRenderNode(rootId, node.getId());
if (node.getClassName().equals(TEXT_CLASS_NAME)) {
Renderer renderer = mRendererWeakRef.get();
if (renderer instanceof NativeRender) {
((NativeRender) renderer).deleteVirtualChildNode(rootId, node.getId());
}
}
node.setNodeFlag(FLAG_ALREADY_DELETED);
node.onDeleted();
}
Expand All @@ -389,6 +400,9 @@ private void removeRenderNode(int rootId, int nodeId) {
RootRenderNode rootNode = NativeRendererManager.getRootNode(rootId);
if (rootId == nodeId) {
NativeRendererManager.removeRootNode(rootId);
if (rootNode != null) {
rootNode.clear();
}
}
if (rootNode != null) {
rootNode.removeRenderNode(nodeId);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,8 @@ public interface NativeRender extends RenderExceptionHandler, RenderLogHandler {
@Nullable
BaseEngineContext getEngineContext();

void deleteVirtualChildNode(int rootId, int nodeId);

int getEngineId();

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -635,6 +635,11 @@ public void updateNode(final int rootId, @NonNull List<Object> nodeList)
}
}

@Override
public void deleteVirtualChildNode(int rootId, int nodeId) {
mVirtualNodeManager.deleteNode(rootId, nodeId);
}

@Override
public void deleteNode(final int rootId, @NonNull int[] ids) throws NativeRenderException {
final List<UITaskExecutor> taskList = new ArrayList<>(ids.length);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,12 +23,13 @@
import com.tencent.renderer.utils.ChoreographerUtils;
import java.util.Map;
import java.util.Map.Entry;
import java.util.concurrent.ConcurrentHashMap;

public class RootRenderNode extends RenderNode {

private final int mRendererId;
private final SparseArray<RenderNode> mNodes = new SparseArray<>(80);
private final SparseArray<VirtualNode> mVirtualNodes = new SparseArray<>(40);
private final ConcurrentHashMap<Integer, VirtualNode> mVirtualNodes = new ConcurrentHashMap<>(40);

public RootRenderNode(int rootId, int id, int rendererId, @NonNull String className,
@NonNull ControllerManager controllerManager) {
Expand Down Expand Up @@ -68,7 +69,7 @@ public void addVirtualNode(@NonNull VirtualNode node) {
}

public void removeVirtualNode(int id) {
mVirtualNodes.delete(id);
mVirtualNodes.remove(id);
}

@Override
Expand Down
Loading