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..0469ea744d9 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,23 @@ public void removeView(View child) { @Override public void removeViewAt(int index) { - View child = getChildAt(index); + View child = getModalChildAt(index); mDialogRootView.removeView(child); } + // Do not directly override the getChildCount method of ModalHostView, as it may cause the crash: + // java.lang.IllegalArgumentException: parameter must be a descendant + // Because under Modal, there are actually no child views. When the system traverses internally, it returns the + // number of child views of mDialogRootView, which leads to inconsistent parent values in the internal + // verification process of the system. + public int getModalChildCount() { + return mDialogRootView.getChildCount(); + } + + public View getModalChildAt(int index) { + return mDialogRootView.getChildAt(index); + } + @Override public boolean dispatchPopulateAccessibilityEvent(AccessibilityEvent event) { return false; @@ -243,7 +246,7 @@ protected void setDialogBar(boolean isDarkIcon) { lp.layoutInDisplayCutoutMode = WindowManager.LayoutParams.LAYOUT_IN_DISPLAY_CUTOUT_MODE_SHORT_EDGES; window.setAttributes(lp); sysUI = sysUI | View.SYSTEM_UI_FLAG_FULLSCREEN - | View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN | View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY; + | View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN | View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY; } else if (mEnterImmersionStatusBar) { sysUI = sysUI & ~View.SYSTEM_UI_FLAG_LIGHT_STATUS_BAR; sysUI = sysUI & ~View.SYSTEM_UI_FLAG_LAYOUT_STABLE;