@@ -17,7 +17,7 @@ import {
17
17
} from "./element-registry" ;
18
18
19
19
import { platformNames , Device } from "tns-core-modules/platform" ;
20
- import { rendererLog as traceLog } from "./trace" ;
20
+ import { viewUtilLog as traceLog } from "./trace" ;
21
21
22
22
const ELEMENT_NODE_TYPE = 1 ;
23
23
const XML_ATTRIBUTES = Object . freeze ( [ "style" , "rows" , "columns" , "fontAttributes" ] ) ;
@@ -94,6 +94,7 @@ export class ViewUtil {
94
94
}
95
95
96
96
private appendToQueue ( parent : NgElement , view : NgElement ) {
97
+ traceLog ( `ViewUtil.appendToQueue parent: ${ parent } view: ${ view } ` ) ;
97
98
if ( parent . lastChild ) {
98
99
parent . lastChild . nextSibling = view ;
99
100
}
@@ -159,24 +160,46 @@ export class ViewUtil {
159
160
}
160
161
161
162
private removeFromQueue ( parent : NgLayoutBase , child : NgView , index : number ) {
163
+ traceLog ( `ViewUtil.removeFromQueue ` +
164
+ `parent: ${ parent } child: ${ child } index: ${ index } ` ) ;
165
+
166
+ if ( parent . firstChild === child && parent . lastChild === child ) {
167
+ parent . firstChild = null ;
168
+ parent . lastChild = null ;
169
+ return ;
170
+ }
171
+
162
172
if ( parent . firstChild === child ) {
163
173
parent . firstChild = child . nextSibling ;
164
174
}
165
175
166
- let previous = ( parent . getChildAt ( index - 1 ) || parent . firstChild ) as NgElement ;
176
+ const previous = this . findPreviousElement ( parent , child , index ) ;
167
177
if ( parent . lastChild === child ) {
168
178
parent . lastChild = previous ;
169
179
}
170
180
181
+ if ( previous ) {
182
+ previous . nextSibling = child . nextSibling ;
183
+ }
184
+ }
185
+
186
+ private findPreviousElement ( parent : NgLayoutBase , child : NgView , elementIndex : number ) : NgElement {
187
+ const previousVisual = this . getPreviousVisualElement ( parent , elementIndex ) ;
188
+ let previous = previousVisual || parent . firstChild ;
189
+
171
190
// since detached elements are not added to the visual tree,
172
191
// we need to find the actual previous sibling of the view,
173
192
// which may as well be an invisible node
174
- while ( previous && previous !== child && isDetachedElement ( previous . nextSibling ) ) {
193
+ while ( previous && previous !== child && previous . nextSibling !== child ) {
175
194
previous = previous . nextSibling ;
176
195
}
177
196
178
- if ( previous ) {
179
- previous . nextSibling = child . nextSibling ;
197
+ return previous ;
198
+ }
199
+
200
+ private getPreviousVisualElement ( parent : NgLayoutBase , elementIndex : number ) : NgElement {
201
+ if ( elementIndex > 0 ) {
202
+ return parent . getChildAt ( elementIndex - 1 ) as NgElement ;
180
203
}
181
204
}
182
205
0 commit comments