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

Commit

Permalink
[iOS] Fix slider crash on iOS9
Browse files Browse the repository at this point in the history
  • Loading branch information
wqyfavor committed Oct 8, 2019
1 parent 9cb3909 commit 7bb97fc
Showing 1 changed file with 12 additions and 4 deletions.
16 changes: 12 additions & 4 deletions ios/sdk/WeexSDK/Sources/Component/WXCycleSliderComponent.mm
Original file line number Diff line number Diff line change
Expand Up @@ -148,10 +148,6 @@ - (UIView *)getItemAtIndex:(NSInteger)index

- (void)setCurrentIndex:(NSInteger)currentIndex
{
if (_currentIndex == currentIndex) {
return;
}

if (currentIndex >= _itemViews.count || currentIndex < 0) {
currentIndex = 0;
}
Expand Down Expand Up @@ -368,12 +364,24 @@ - (void)scrollViewDidEndDecelerating:(UIScrollView *)scrollView {
}

- (void)scrollViewDidEndScrollingAnimation:(UIScrollView *)scrollView {
/* In this case, we forbid animation temporarily so that
setContentOffset in setCurrentIndex won't cause endless loop
on some devices.
We have to use _forbidSlideAnimation in setCurrentIndex because
sometimes JS will trigger the slider to slide to some posistion
with animation.
*/
BOOL oldValue = _forbidSlideAnimation;
_forbidSlideAnimation = YES;

if (_infinite) {
[self resetScrollView];
} else {
NSInteger index = _scrollView.contentOffset.x / self.width;
[self setCurrentIndex:index];
}

_forbidSlideAnimation = oldValue;
}

@end
Expand Down

0 comments on commit 7bb97fc

Please sign in to comment.