* Inserts a view at the specified index. * * When the view already is in the stack it will be moved to the new position. * * @param view The view to insert. * @param index The index where to insert the view.
(view: ViewController, index: number)
| 955 | * @param index The index where to insert the view. |
| 956 | */ |
| 957 | private insertViewAt(view: ViewController, index: number) { |
| 958 | const views = this.views; |
| 959 | const existingIndex = views.indexOf(view); |
| 960 | if (existingIndex > -1) { |
| 961 | assert(view.nav === this, 'view is not part of the nav'); |
| 962 | // The view already in the stack, removes it. |
| 963 | views.splice(existingIndex, 1); |
| 964 | // and add it back at the requested index. |
| 965 | views.splice(index, 0, view); |
| 966 | } else { |
| 967 | assert(!view.nav, 'nav is used'); |
| 968 | // this is a new view to add to the stack |
| 969 | // create the new entering view |
| 970 | view.nav = this; |
| 971 | views.splice(index, 0, view); |
| 972 | } |
| 973 | } |
| 974 | |
| 975 | /** |
| 976 | * Removes a view from the stack. |