mirror of
https://github.com/NativeScript/NativeScript.git
synced 2025-08-14 01:43:14 +08:00
fix(core): ignore inserting child if < 0 (#10690)
This commit is contained in:
@ -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 {
|
||||
|
2
packages/core/ui/layouts/layout-base.d.ts
vendored
2
packages/core/ui/layouts/layout-base.d.ts
vendored
@ -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.
|
||||
|
@ -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 {
|
||||
|
@ -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) {
|
||||
|
Reference in New Issue
Block a user