fix(core): ignore inserting child if < 0 (#10690)

This commit is contained in:
Nathan Walker
2025-02-05 09:59:30 -08:00
committed by GitHub
parent 3a7206fc3b
commit 2305511187
4 changed files with 29 additions and 23 deletions

View File

@ -49,14 +49,14 @@ export class LayoutBaseCommon extends CustomLayoutView implements LayoutBaseDefi
this._registerLayoutChild(child);
}
public insertChild(child: View, atIndex: number): void {
if (atIndex < 0) {
throw new Error('Cannot insert a child to a negative index.');
public insertChild(child: View, atIndex: number): boolean {
if (atIndex > -1) {
this._subViews.splice(atIndex, 0, child);
this._addView(child, atIndex);
this._registerLayoutChild(child);
return true;
}
this._subViews.splice(atIndex, 0, child);
this._addView(child, atIndex);
this._registerLayoutChild(child);
return false;
}
public removeChild(child: View): void {

View File

@ -34,7 +34,7 @@ export class LayoutBase extends CustomLayoutView {
* @param view The view to be added to the end of the children array.
* @param atIndex The insertion index.
*/
insertChild(child: View, atIndex: number): void;
insertChild(child: View, atIndex: number): boolean;
/**
* Removes the specified view from the children array.

View File

@ -11,9 +11,12 @@ export class LayoutBase extends LayoutBaseCommon {
this.requestLayout();
}
public insertChild(child: View, atIndex: number): void {
super.insertChild(child, atIndex);
this.requestLayout();
public insertChild(child: View, atIndex: number): boolean {
if (super.insertChild(child, atIndex)) {
this.requestLayout();
return true;
}
return false;
}
public removeChild(child: View): void {

View File

@ -8,20 +8,23 @@ import { LinearGradient } from '../../styling/linear-gradient';
export * from './root-layout-common';
export class RootLayout extends RootLayoutBase {
insertChild(view: View, atIndex: number): void {
super.insertChild(view, atIndex);
if (!view.hasGestureObservers()) {
// block tap events from going through to layers behind the view
if (view.nativeViewProtected) {
view.nativeViewProtected.setOnTouchListener(
new android.view.View.OnTouchListener({
onTouch: function (view, event) {
return true;
},
}),
);
insertChild(view: View, atIndex: number): boolean {
if (super.insertChild(view, atIndex)) {
if (!view.hasGestureObservers()) {
// block tap events from going through to layers behind the view
if (view.nativeViewProtected) {
view.nativeViewProtected.setOnTouchListener(
new android.view.View.OnTouchListener({
onTouch: function (view, event) {
return true;
},
}),
);
}
}
return true;
}
return false;
}
removeChild(view: View): void {
if (view.hasGestureObservers() && view.nativeViewProtected) {