2222 * Pixel amounts or percentages are allowed (see below).
2323 * 3. The elements rendered will be absolutely positioned: be sure to let your CSS work with
2424 * this (see below).
25- * 4. Keep the HTML of your repeated elements as simple as possible.
26- * The more complicated your elements, the more likely it is that the on-demand compilation will cause
27- * some jerkiness in the user's scrolling.
28- * 6. Each collection-repeat list will take up all of its parent scrollView's space.
25+ * 4. Each collection-repeat list will take up all of its parent scrollView's space.
2926 * If you wish to have multiple lists on one page, put each list within its own
3027 * {@link ionic.directive:ionScroll ionScroll} container.
31- * 7 . You should not use the ng-show and ng-hide directives on your ion-content/ion-scroll elements that
28+ * 5 . You should not use the ng-show and ng-hide directives on your ion-content/ion-scroll elements that
3229 * have a collection-repeat inside. ng-show and ng-hide apply the `display: none` css rule to the content's
3330 * style, causing the scrollView to read the width and height of the content as 0. Resultingly,
3431 * collection-repeat will render elements that have just been un-hidden incorrectly.
@@ -154,6 +151,10 @@ function($collectionRepeatManager, $collectionDataSource, $parse) {
154151 require : '^$ionicScroll' ,
155152 controller : [ function ( ) { } ] ,
156153 link : function ( $scope , $element , $attr , scrollCtrl , $transclude ) {
154+ var wrap = jqLite ( '<div style="position:relative;">' ) ;
155+ $element . parent ( ) [ 0 ] . insertBefore ( wrap [ 0 ] , $element [ 0 ] ) ;
156+ wrap . append ( $element ) ;
157+
157158 var scrollView = scrollCtrl . scrollView ;
158159 if ( scrollView . options . scrollingX && scrollView . options . scrollingY ) {
159160 throw new Error ( COLLECTION_REPEAT_SCROLLVIEW_XY_ERROR ) ;
@@ -216,9 +217,32 @@ function($collectionRepeatManager, $collectionDataSource, $parse) {
216217 rerender ( value ) ;
217218 } ) ;
218219
220+ var scrollViewContent = scrollCtrl . scrollView . __content ;
219221 function rerender ( value ) {
222+ var beforeSiblings = [ ] ;
223+ var afterSiblings = [ ] ;
224+ var before = true ;
225+ forEach ( scrollViewContent . children , function ( node , i ) {
226+ if ( ionic . DomUtil . elementIsDescendant ( $element [ 0 ] , node , scrollViewContent ) ) {
227+ before = false ;
228+ } else {
229+ var width = node . offsetWidth ;
230+ var height = node . offsetHeight ;
231+ if ( width && height ) {
232+ var element = jqLite ( node ) ;
233+ ( before ? beforeSiblings : afterSiblings ) . push ( {
234+ width : node . offsetWidth ,
235+ height : node . offsetHeight ,
236+ element : element ,
237+ scope : element . isolateScope ( ) || element . scope ( ) ,
238+ isOutside : true
239+ } ) ;
240+ }
241+ }
242+ } ) ;
243+
220244 scrollView . resize ( ) ;
221- dataSource . setData ( value ) ;
245+ dataSource . setData ( value , beforeSiblings , afterSiblings ) ;
222246 collectionRepeatManager . resize ( ) ;
223247 }
224248 function onWindowResize ( ) {
@@ -237,7 +261,7 @@ function($collectionRepeatManager, $collectionDataSource, $parse) {
237261} ] ) ;
238262
239263// Fix for #1674
240- // Problem: if an ngSrc or ngHref expression evaluates to a falsy value, it will
264+ // Problem: if an ngSrc or ngHref expression evaluates to a falsy value, it will
241265// not erase the previous truthy value of the href.
242266// In collectionRepeat, we re-use elements from before. So if the ngHref expression
243267// evaluates to truthy for item 1 and then falsy for item 2, if an element changes
@@ -248,13 +272,13 @@ function collectionRepeatSrcDirective(ngAttrName, attrName) {
248272 return [ function ( ) {
249273 return {
250274 priority : '99' , // it needs to run after the attributes are interpolated
251- require : '^?collectionRepeat' ,
252275 link : function ( scope , element , attr , collectionRepeatCtrl ) {
253276 if ( ! collectionRepeatCtrl ) return ;
254277 attr . $observe ( ngAttrName , function ( value ) {
255- if ( ! value ) {
256- element . removeAttr ( attrName ) ;
257- }
278+ element [ 0 ] [ attr ] = '' ;
279+ setTimeout ( function ( ) {
280+ element [ 0 ] [ attr ] = value ;
281+ } ) ;
258282 } ) ;
259283 }
260284 } ;
0 commit comments