mirror of
https://github.com/NativeScript/NativeScript.git
synced 2025-08-15 19:26:42 +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) => {
|
this._closeModalCallback = (...originalArgs) => {
|
||||||
const cleanupModalViews = () => {
|
const cleanupModalViews = () => {
|
||||||
const modalIndex = _rootModalViews.indexOf(this);
|
const modalIndex = _rootModalViews.indexOf(this);
|
||||||
_rootModalViews.splice(modalIndex, 1);
|
if (modalIndex > -1) {
|
||||||
|
_rootModalViews.splice(modalIndex, 1);
|
||||||
|
}
|
||||||
|
|
||||||
this._modalParent = null;
|
this._modalParent = null;
|
||||||
this._modalContext = null;
|
this._modalContext = null;
|
||||||
this._closeModalCallback = null;
|
this._closeModalCallback = null;
|
||||||
|
@ -50,6 +50,10 @@ export class LayoutBaseCommon extends CustomLayoutView implements LayoutBaseDefi
|
|||||||
}
|
}
|
||||||
|
|
||||||
public insertChild(child: View, atIndex: number): void {
|
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._subViews.splice(atIndex, 0, child);
|
||||||
this._addView(child, atIndex);
|
this._addView(child, atIndex);
|
||||||
this._registerLayoutChild(child);
|
this._registerLayoutChild(child);
|
||||||
@ -60,8 +64,10 @@ export class LayoutBaseCommon extends CustomLayoutView implements LayoutBaseDefi
|
|||||||
|
|
||||||
// TODO: consider caching the index on the child.
|
// TODO: consider caching the index on the child.
|
||||||
const index = this._subViews.indexOf(child);
|
const index = this._subViews.indexOf(child);
|
||||||
this._subViews.splice(index, 1);
|
if (index > -1) {
|
||||||
this._unregisterLayoutChild(child);
|
this._subViews.splice(index, 1);
|
||||||
|
this._unregisterLayoutChild(child);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public removeChildren(): void {
|
public removeChildren(): void {
|
||||||
|
@ -93,10 +93,10 @@ export class RootLayoutBase extends GridLayout {
|
|||||||
},
|
},
|
||||||
(err) => {
|
(err) => {
|
||||||
rej(new Error(`Error playing enter animation: ${err}`));
|
rej(new Error(`Error playing enter animation: ${err}`));
|
||||||
}
|
},
|
||||||
);
|
);
|
||||||
});
|
});
|
||||||
})
|
}),
|
||||||
);
|
);
|
||||||
|
|
||||||
Promise.all(toOpen).then(
|
Promise.all(toOpen).then(
|
||||||
@ -105,7 +105,7 @@ export class RootLayoutBase extends GridLayout {
|
|||||||
},
|
},
|
||||||
(err) => {
|
(err) => {
|
||||||
reject(err);
|
reject(err);
|
||||||
}
|
},
|
||||||
);
|
);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
@ -140,7 +140,9 @@ export class RootLayoutBase extends GridLayout {
|
|||||||
const exitAnimationDefinition = exitTo || poppedView?.options?.animation?.exitTo;
|
const exitAnimationDefinition = exitTo || poppedView?.options?.animation?.exitTo;
|
||||||
|
|
||||||
// Remove view from tracked popupviews
|
// Remove view from tracked popupviews
|
||||||
this.popupViews.splice(popupIndex, 1);
|
if (popupIndex > -1) {
|
||||||
|
this.popupViews.splice(popupIndex, 1);
|
||||||
|
}
|
||||||
|
|
||||||
toClose.push(
|
toClose.push(
|
||||||
new Promise<void>((res, rej) => {
|
new Promise<void>((res, rej) => {
|
||||||
@ -153,7 +155,7 @@ export class RootLayoutBase extends GridLayout {
|
|||||||
} else {
|
} else {
|
||||||
res();
|
res();
|
||||||
}
|
}
|
||||||
})
|
}),
|
||||||
);
|
);
|
||||||
|
|
||||||
if (this.shadeCover) {
|
if (this.shadeCover) {
|
||||||
@ -177,7 +179,7 @@ export class RootLayoutBase extends GridLayout {
|
|||||||
},
|
},
|
||||||
(err) => {
|
(err) => {
|
||||||
reject(err);
|
reject(err);
|
||||||
}
|
},
|
||||||
);
|
);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
@ -264,8 +266,8 @@ export class RootLayoutBase extends GridLayout {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// keep the popupViews array in sync with the stacking of the views
|
// keep the popupViews array in sync with the stacking of the views
|
||||||
const currentView = this.popupViews[this.getPopupIndex(view)];
|
const currentView = this.popupViews[popupIndex];
|
||||||
this.popupViews.splice(this.getPopupIndex(view), 1);
|
this.popupViews.splice(popupIndex, 1);
|
||||||
this.popupViews.push(currentView);
|
this.popupViews.push(currentView);
|
||||||
|
|
||||||
const exitAnimation = this.getViewExitState(view);
|
const exitAnimation = this.getViewExitState(view);
|
||||||
|
Reference in New Issue
Block a user