mirror of
https://github.com/NativeScript/NativeScript.git
synced 2025-08-14 01:43:14 +08:00
fix(core): avoid splicing arrays using a negative start index (#10679)
This commit is contained in:

committed by
GitHub

parent
20fc1cc1d4
commit
9bd147c9d0
@ -447,7 +447,10 @@ export abstract class ViewCommon extends ViewBase implements ViewDefinition {
|
||||
this._closeModalCallback = (...originalArgs) => {
|
||||
const cleanupModalViews = () => {
|
||||
const modalIndex = _rootModalViews.indexOf(this);
|
||||
_rootModalViews.splice(modalIndex, 1);
|
||||
if (modalIndex > -1) {
|
||||
_rootModalViews.splice(modalIndex, 1);
|
||||
}
|
||||
|
||||
this._modalParent = null;
|
||||
this._modalContext = null;
|
||||
this._closeModalCallback = null;
|
||||
|
@ -50,6 +50,10 @@ export class LayoutBaseCommon extends CustomLayoutView implements LayoutBaseDefi
|
||||
}
|
||||
|
||||
public insertChild(child: View, atIndex: number): void {
|
||||
if (atIndex < 0) {
|
||||
throw new Error('Cannot insert a child to a negative index.');
|
||||
}
|
||||
|
||||
this._subViews.splice(atIndex, 0, child);
|
||||
this._addView(child, atIndex);
|
||||
this._registerLayoutChild(child);
|
||||
@ -60,8 +64,10 @@ export class LayoutBaseCommon extends CustomLayoutView implements LayoutBaseDefi
|
||||
|
||||
// TODO: consider caching the index on the child.
|
||||
const index = this._subViews.indexOf(child);
|
||||
this._subViews.splice(index, 1);
|
||||
this._unregisterLayoutChild(child);
|
||||
if (index > -1) {
|
||||
this._subViews.splice(index, 1);
|
||||
this._unregisterLayoutChild(child);
|
||||
}
|
||||
}
|
||||
|
||||
public removeChildren(): void {
|
||||
|
@ -93,10 +93,10 @@ export class RootLayoutBase extends GridLayout {
|
||||
},
|
||||
(err) => {
|
||||
rej(new Error(`Error playing enter animation: ${err}`));
|
||||
}
|
||||
},
|
||||
);
|
||||
});
|
||||
})
|
||||
}),
|
||||
);
|
||||
|
||||
Promise.all(toOpen).then(
|
||||
@ -105,7 +105,7 @@ export class RootLayoutBase extends GridLayout {
|
||||
},
|
||||
(err) => {
|
||||
reject(err);
|
||||
}
|
||||
},
|
||||
);
|
||||
});
|
||||
}
|
||||
@ -140,7 +140,9 @@ export class RootLayoutBase extends GridLayout {
|
||||
const exitAnimationDefinition = exitTo || poppedView?.options?.animation?.exitTo;
|
||||
|
||||
// Remove view from tracked popupviews
|
||||
this.popupViews.splice(popupIndex, 1);
|
||||
if (popupIndex > -1) {
|
||||
this.popupViews.splice(popupIndex, 1);
|
||||
}
|
||||
|
||||
toClose.push(
|
||||
new Promise<void>((res, rej) => {
|
||||
@ -153,7 +155,7 @@ export class RootLayoutBase extends GridLayout {
|
||||
} else {
|
||||
res();
|
||||
}
|
||||
})
|
||||
}),
|
||||
);
|
||||
|
||||
if (this.shadeCover) {
|
||||
@ -177,7 +179,7 @@ export class RootLayoutBase extends GridLayout {
|
||||
},
|
||||
(err) => {
|
||||
reject(err);
|
||||
}
|
||||
},
|
||||
);
|
||||
});
|
||||
}
|
||||
@ -264,8 +266,8 @@ export class RootLayoutBase extends GridLayout {
|
||||
}
|
||||
|
||||
// keep the popupViews array in sync with the stacking of the views
|
||||
const currentView = this.popupViews[this.getPopupIndex(view)];
|
||||
this.popupViews.splice(this.getPopupIndex(view), 1);
|
||||
const currentView = this.popupViews[popupIndex];
|
||||
this.popupViews.splice(popupIndex, 1);
|
||||
this.popupViews.push(currentView);
|
||||
|
||||
const exitAnimation = this.getViewExitState(view);
|
||||
|
Reference in New Issue
Block a user