From 1248b02b16d84337ee6dc5805a75eb506a005097 Mon Sep 17 00:00:00 2001 From: siguangli Date: Mon, 14 Oct 2024 11:13:18 +0800 Subject: [PATCH] fix(android): modal host view crash --- .../hippy/uimanager/HippyViewController.java | 9 +++++++-- .../views/modal/HippyModalHostManager.java | 10 ++++++++++ .../hippy/views/modal/HippyModalHostView.java | 20 +++++++++---------- 3 files changed, 26 insertions(+), 13 deletions(-) diff --git a/renderer/native/android/src/main/java/com/tencent/mtt/hippy/uimanager/HippyViewController.java b/renderer/native/android/src/main/java/com/tencent/mtt/hippy/uimanager/HippyViewController.java index d6bcb0fa233..be449deac6e 100644 --- a/renderer/native/android/src/main/java/com/tencent/mtt/hippy/uimanager/HippyViewController.java +++ b/renderer/native/android/src/main/java/com/tencent/mtt/hippy/uimanager/HippyViewController.java @@ -37,6 +37,7 @@ import com.tencent.mtt.hippy.views.common.HippyNestedScrollComponent.Priority; import com.tencent.mtt.hippy.views.common.HippyNestedScrollHelper; import com.tencent.mtt.hippy.views.custom.HippyCustomPropsController; +import com.tencent.mtt.hippy.views.modal.HippyModalHostView; import com.tencent.mtt.hippy.views.view.HippyViewGroup; import com.tencent.renderer.NativeRenderContext; import com.tencent.renderer.Renderer; @@ -543,8 +544,12 @@ private boolean checkOverflowVisible(@NonNull View view) { protected void addView(ViewGroup parentView, View view, int index) { int realIndex = index; - if (realIndex > parentView.getChildCount()) { - realIndex = parentView.getChildCount(); + int childCount = parentView.getChildCount(); + if (parentView instanceof HippyModalHostView) { + childCount = ((HippyModalHostView) parentView).getModalChildCount(); + } + if (realIndex > childCount) { + realIndex = childCount; } try { parentView.addView(view, realIndex); diff --git a/renderer/native/android/src/main/java/com/tencent/mtt/hippy/views/modal/HippyModalHostManager.java b/renderer/native/android/src/main/java/com/tencent/mtt/hippy/views/modal/HippyModalHostManager.java index f819745f19f..a62f732a061 100644 --- a/renderer/native/android/src/main/java/com/tencent/mtt/hippy/views/modal/HippyModalHostManager.java +++ b/renderer/native/android/src/main/java/com/tencent/mtt/hippy/views/modal/HippyModalHostManager.java @@ -20,6 +20,7 @@ import android.content.DialogInterface; import android.view.View; +import android.view.ViewGroup; import androidx.annotation.NonNull; import com.tencent.mtt.hippy.annotation.HippyController; import com.tencent.mtt.hippy.annotation.HippyControllerProps; @@ -101,4 +102,13 @@ public void onAfterUpdateProps(@NonNull HippyModalHostView v) { v.showOrUpdate(); } + @Override + public int getChildCount(HippyModalHostView modalHostView) { + return modalHostView.getModalChildCount(); + } + + @Override + public View getChildAt(HippyModalHostView modalHostView, int i) { + return modalHostView.getModalChildAt(i); + } } diff --git a/renderer/native/android/src/main/java/com/tencent/mtt/hippy/views/modal/HippyModalHostView.java b/renderer/native/android/src/main/java/com/tencent/mtt/hippy/views/modal/HippyModalHostView.java index de6e82e72f9..c33a4ab297e 100644 --- a/renderer/native/android/src/main/java/com/tencent/mtt/hippy/views/modal/HippyModalHostView.java +++ b/renderer/native/android/src/main/java/com/tencent/mtt/hippy/views/modal/HippyModalHostView.java @@ -126,16 +126,6 @@ public void addView(View child, int index) { mDialogRootView.addView(child, index); } - @Override - public int getChildCount() { - return mDialogRootView.getChildCount(); - } - - @Override - public View getChildAt(int index) { - return mDialogRootView.getChildAt(index); - } - @Override public void removeView(View child) { mDialogRootView.removeView(child); @@ -143,10 +133,18 @@ public void removeView(View child) { @Override public void removeViewAt(int index) { - View child = getChildAt(index); + View child = getModalChildAt(index); mDialogRootView.removeView(child); } + public int getModalChildCount() { + return mDialogRootView.getChildCount(); + } + + public View getModalChildAt(int index) { + return mDialogRootView.getChildAt(index); + } + @Override public boolean dispatchPopulateAccessibilityEvent(AccessibilityEvent event) { return false;