ionic-framework icon indicating copy to clipboard operation
ionic-framework copied to clipboard

SlideBox update() doesn't work with left-growing array

Open guillermin opened this issue 12 years ago • 10 comments

When adding elements to the slidebox input array (ng-repeat) at the end of the array with push(), an update() works as expected: the new slides are added and the current slide is shown. If elements are added at the beginning of the array (unshift()), the update() is not working properly: the indexes don't adjust to the current position of the actual element.

guillermin avatar Apr 28 '14 15:04 guillermin

I've made a CodePen example to illustrate the problem: http://codepen.io/anon/pen/rtiyB

guillermin avatar Apr 28 '14 16:04 guillermin

@guillermin thanks for the code pen. I'm still trying to understand the issue. What exactly should happen here?

mlynch avatar Apr 28 '14 17:04 mlynch

Basically, when you add a color to the left, you also "move" left because your index is now off by 1, since adding an element at 0 makes all previous items increment their index by 1.

This does not happen when adding an element to the right, where the new element gets a new (autoincrementing) index and everything else stays the same.

I've managed a workaround in my app with:

setTimeout(function(){
  $ionicSlideBoxDelegate.slide($ionicSlideBoxDelegate.currentIndex()+1));
});

but it produces a noticeable flicker. I was hoping to implement it directly in update() so the index could be updated before setup(), and therefore require no extra slide().

guillermin avatar Apr 28 '14 23:04 guillermin

Ah I see what you mean @guillermin. Thanks.

ajoslin avatar Apr 29 '14 18:04 ajoslin

I'm having the same issue, but I'm trying to do a $scope.data.splice(n, 1); sort of situation.

It seems that adding an element works better than removing. Removing puts the whole slidebox into a broken state. You can verify this in the CodePen above by changing the unshift() to be a splice(0, 1). Any workarounds for this would be much appreciated.

motionsmith avatar Jul 03 '14 18:07 motionsmith

This appears to be fixed with @ajoslin's update to slidebox http://codepen.io/perrygovier/pen/gCplv

perrygovier avatar Aug 06 '14 15:08 perrygovier

There is still an issue with left-shrinking arrays. Open up the codepen above and change the unshift() to shift() (make sure you're currentIndex() is 1 so you don't unshift yourself off a cliff).

When you click on the slidebox, the entire view disappears.

motionsmith avatar Aug 07 '14 00:08 motionsmith

I am trying the exact same thing @motionsmith is doing, any help would be appreciated. Slide box slipce puts the entire slide box into a broken state. if i splice the first index (0) it doesn't update and overlaps with last index image.

scripterkaran avatar Mar 30 '15 05:03 scripterkaran

+1 any news on this?

phasnox avatar May 25 '15 21:05 phasnox

any update on this?

yingzhox avatar Aug 26 '15 05:08 yingzhox