@@ -138,30 +138,37 @@ function CollectionRepeatDirective($ionicCollectionManager, $parse, $window, $$r
138
138
139
139
var afterItemsContainer = initAfterItemsContainer ( ) ;
140
140
141
+ var changeValidator = makeChangeValidator ( ) ;
141
142
initDimensions ( ) ;
142
143
143
144
// Dimensions are refreshed on resize or data change.
144
- angular . element ( $window ) . on ( 'resize' , validateResize ) ;
145
145
scrollCtrl . $element . on ( 'scroll.resize' , refreshDimensions ) ;
146
- var unlistenToExposeAside = $rootScope . $on ( '$ionicExposeAside' , validateResize ) ;
146
+
147
+ angular . element ( $window ) . on ( 'resize' , onResize ) ;
148
+ var unlistenToExposeAside = $rootScope . $on ( '$ionicExposeAside' , onResize ) ;
147
149
$timeout ( refreshDimensions , 0 , false ) ;
148
150
151
+ function onResize ( ) {
152
+ if ( changeValidator . resizeRequiresRefresh ( scrollView . __clientWidth , scrollView . __clientHeight ) ) {
153
+ refreshDimensions ( ) ;
154
+ }
155
+ }
156
+
149
157
scope . $watchCollection ( listGetter , function ( newValue ) {
150
158
data = newValue || ( newValue = [ ] ) ;
151
159
if ( ! angular . isArray ( newValue ) ) {
152
160
throw new Error ( "collection-repeat expected an array for '" + listExpr + "', " +
153
161
"but got a " + typeof value ) ;
154
162
}
155
-
156
163
// Wait for this digest to end before refreshing everything.
157
164
scope . $$postDigest ( function ( ) {
158
- getRepeatManager ( ) . refreshData ( newValue ) ;
159
- refreshDimensions ( ) ;
165
+ getRepeatManager ( ) . setData ( data ) ;
166
+ if ( changeValidator . dataChangeRequiresRefresh ( data ) ) refreshDimensions ( ) ;
160
167
} ) ;
161
168
} ) ;
162
169
163
170
scope . $on ( '$destroy' , function ( ) {
164
- angular . element ( $window ) . off ( 'resize' , validateResize ) ;
171
+ angular . element ( $window ) . off ( 'resize' , onResize ) ;
165
172
unlistenToExposeAside ( ) ;
166
173
scrollCtrl . $element && scrollCtrl . $element . off ( 'scroll.resize' , refreshDimensions ) ;
167
174
@@ -174,6 +181,32 @@ function CollectionRepeatDirective($ionicCollectionManager, $parse, $window, $$r
174
181
repeatManager = null ;
175
182
} ) ;
176
183
184
+ function makeChangeValidator ( ) {
185
+ var self ;
186
+ return ( self = {
187
+ dataLength : 0 ,
188
+ width : 0 ,
189
+ height : 0 ,
190
+ resizeRequiresRefresh : function ( newWidth , newHeight ) {
191
+ var requiresRefresh = self . dataLength &&
192
+ newWidth && newWidth !== self . width &&
193
+ newHeight && newHeight !== self . height ;
194
+
195
+ self . width = newWidth ;
196
+ self . height = newHeight ;
197
+
198
+ return ! ! requiresRefresh ;
199
+ } ,
200
+ dataChangeRequiresRefresh : function ( newData ) {
201
+ var requiresRefresh = newData . length > 0 || newData . length < self . dataLength ;
202
+
203
+ self . dataLength = newData . length ;
204
+
205
+ return ! ! requiresRefresh ;
206
+ }
207
+ } ) ;
208
+ }
209
+
177
210
function getRepeatManager ( ) {
178
211
return repeatManager || ( repeatManager = new $ionicCollectionManager ( {
179
212
afterItemsNode : afterItemsContainer [ 0 ] ,
@@ -242,23 +275,14 @@ function CollectionRepeatDirective($ionicCollectionManager, $parse, $window, $$r
242
275
}
243
276
}
244
277
245
- // Make sure this resize actually changed the size of the screen
246
- function validateResize ( ) {
247
- var h = scrollView . __clientHeight , w = scrollView . __clientWidth ;
248
- if ( w && h && ( validateResize . height !== h || validateResize . width !== w ) ) {
249
- validateResize . height = h ;
250
- validateResize . width = w ;
251
- refreshDimensions ( ) ;
252
- }
253
- }
254
278
function refreshDimensions ( ) {
255
- if ( ! data . length ) return ;
279
+ var hasData = data . length > 0 ;
256
280
257
- if ( heightData . computed || widthData . computed ) {
281
+ if ( hasData && ( heightData . computed || widthData . computed ) ) {
258
282
computeStyleDimensions ( ) ;
259
283
}
260
284
261
- if ( heightData . computed ) {
285
+ if ( hasData && heightData . computed ) {
262
286
heightData . value = computedStyleDimensions . height ;
263
287
if ( ! heightData . value ) {
264
288
throw new Error ( 'collection-repeat tried to compute the height of repeated elements "' +
@@ -269,7 +293,8 @@ function CollectionRepeatDirective($ionicCollectionManager, $parse, $window, $$r
269
293
// If it's a constant with a getter (eg percent), we just refresh .value after resize
270
294
heightData . value = heightData . getValue ( ) ;
271
295
}
272
- if ( widthData . computed ) {
296
+
297
+ if ( hasData && widthData . computed ) {
273
298
widthData . value = computedStyleDimensions . width ;
274
299
if ( ! widthData . value ) {
275
300
throw new Error ( 'collection-repeat tried to compute the width of repeated elements "' +
@@ -527,7 +552,7 @@ function RepeatManagerFactory($rootScope, $window, $$rAF) {
527
552
}
528
553
} ;
529
554
530
- this . refreshData = function ( newData ) {
555
+ this . setData = function ( newData ) {
531
556
data = newData ;
532
557
( view . onRefreshData || angular . noop ) ( ) ;
533
558
isDataReady = true ;
0 commit comments