Skip to content
This repository was archived by the owner on Jun 3, 2021. It is now read-only.

Commit 7bb97fc

Browse files
author
wqyfavor
authored
[iOS] Fix slider crash on iOS9
1 parent 9cb3909 commit 7bb97fc

File tree

1 file changed

+12
-4
lines changed

1 file changed

+12
-4
lines changed

ios/sdk/WeexSDK/Sources/Component/WXCycleSliderComponent.mm

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -148,10 +148,6 @@ - (UIView *)getItemAtIndex:(NSInteger)index
148148

149149
- (void)setCurrentIndex:(NSInteger)currentIndex
150150
{
151-
if (_currentIndex == currentIndex) {
152-
return;
153-
}
154-
155151
if (currentIndex >= _itemViews.count || currentIndex < 0) {
156152
currentIndex = 0;
157153
}
@@ -368,12 +364,24 @@ - (void)scrollViewDidEndDecelerating:(UIScrollView *)scrollView {
368364
}
369365

370366
- (void)scrollViewDidEndScrollingAnimation:(UIScrollView *)scrollView {
367+
/* In this case, we forbid animation temporarily so that
368+
setContentOffset in setCurrentIndex won't cause endless loop
369+
on some devices.
370+
We have to use _forbidSlideAnimation in setCurrentIndex because
371+
sometimes JS will trigger the slider to slide to some posistion
372+
with animation.
373+
*/
374+
BOOL oldValue = _forbidSlideAnimation;
375+
_forbidSlideAnimation = YES;
376+
371377
if (_infinite) {
372378
[self resetScrollView];
373379
} else {
374380
NSInteger index = _scrollView.contentOffset.x / self.width;
375381
[self setCurrentIndex:index];
376382
}
383+
384+
_forbidSlideAnimation = oldValue;
377385
}
378386

379387
@end

0 commit comments

Comments
 (0)