Skip to content

Commit

Permalink
fix(android): modal host view crash
Browse files Browse the repository at this point in the history
  • Loading branch information
siguangli2018 committed Oct 14, 2024
1 parent ed0dd23 commit 1248b02
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -126,27 +126,25 @@ 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);
}

@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;
Expand Down

0 comments on commit 1248b02

Please sign in to comment.