Skip to content

Commit

Permalink
fix(android): call bridge destroy after destroy driver
Browse files Browse the repository at this point in the history
  • Loading branch information
siguangli2018 committed Aug 8, 2023
1 parent c227cb4 commit 04debb2
Show file tree
Hide file tree
Showing 5 changed files with 27 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -1038,7 +1038,6 @@ public void destroy(boolean isReload) {
if (!isReload) {
mDomManager.destroy();
}
mBridgeManager.destroy();
mModuleManager.destroy();
mVfsManager.destroy();
onDestroyVfs(mVfsManager.getId());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -213,6 +213,9 @@ public void Call(long result, Message message, String action, String reason) {
mCallFunctionCallback = null;
}
}, (msg.arg1 == DESTROY_RELOAD));
// When the driver is destroyed, the corresponding scope is also cleared, so there can
// be no more call function calls, destroy needs to be called here.
destroy();
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,10 @@ class HippyEngineHelper {
hippyEngineList.remove(hippyEngineWrapper)
abandonHippyEngineList.add(hippyEngineWrapper)
}

fun clearAbandonHippyEngine() {
abandonHippyEngineList.clear()
}
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,11 @@ class MainActivity : AppCompatActivity() {
setContentView(activityMainRoot)
}

override fun onResume() {
super.onResume()
HippyEngineHelper.clearAbandonHippyEngine()
}

private fun intPageMain() {
val pageManagementButton = activityMainRoot.findViewById<View>(R.id.page_management_button)
val pageManagementImage =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@
import com.tencent.renderer.utils.PropertyUtils;
import com.tencent.renderer.utils.PropertyUtils.PropertyMethodHolder;

import java.lang.ref.WeakReference;
import java.lang.reflect.Method;
import java.util.ArrayList;
import java.util.HashMap;
Expand All @@ -61,10 +62,10 @@ public class VirtualNodeManager {
*/
private final Map<Integer, List<VirtualNode>> mUpdateNodes = new HashMap<>();
@NonNull
private final NativeRender mNativeRenderer;
private final WeakReference<NativeRender> mNativeRendererRef;

public VirtualNodeManager(@NonNull NativeRender nativeRenderer) {
mNativeRenderer = nativeRenderer;
mNativeRendererRef = new WeakReference<>(nativeRenderer);
}

/**
Expand Down Expand Up @@ -250,9 +251,11 @@ private void invokePropertyMethod(@NonNull VirtualNode node, @NonNull Map props,
PropertyUtils.convertProperty(methodHolder.paramTypes[0], value));
}
} catch (Exception exception) {
mNativeRenderer.handleRenderException(
PropertyUtils
.makePropertyConvertException(exception, key, methodHolder.method));
if (mNativeRendererRef.get() != null) {
mNativeRendererRef.get().handleRenderException(
PropertyUtils
.makePropertyConvertException(exception, key, methodHolder.method));
}
}
}

Expand All @@ -279,17 +282,21 @@ private void updateProps(@NonNull VirtualNode node, @Nullable Map<String, Object
@Nullable
private VirtualNode createVirtualNode(int rootId, int id, int pid, int index,
@NonNull String className, @Nullable Map<String, Object> props) {
VirtualNode node = mNativeRenderer.createVirtualNode(rootId, id, pid, index, className,
NativeRender nativeRender = mNativeRendererRef.get();
if (nativeRender == null) {
return null;
}
VirtualNode node = nativeRender.createVirtualNode(rootId, id, pid, index, className,
props);
VirtualNode parent = getVirtualNode(rootId, pid);
// Only text、text child and text input need to create virtual node.
if (className.equals(TEXT_CLASS_NAME)) {
if (!(node instanceof TextVirtualNode)) {
node = new TextVirtualNode(rootId, id, pid, index, mNativeRenderer);
node = new TextVirtualNode(rootId, id, pid, index, nativeRender);
}
} else if (className.equals(IMAGE_CLASS_NAME) && parent != null) {
if (!(node instanceof ImageVirtualNode)) {
node = new ImageVirtualNode(rootId, id, pid, index, mNativeRenderer);
node = new ImageVirtualNode(rootId, id, pid, index, nativeRender);
}
} else if (className.equals(TEXT_INPUT_CLASS_NAME)) {
if (!(node instanceof TextInputVirtualNode)) {
Expand Down

0 comments on commit 04debb2

Please sign in to comment.