From fe6f8c9a14bb484ef6787cc6a54dd74af84661bd Mon Sep 17 00:00:00 2001 From: wqyfavor Date: Fri, 30 Nov 2018 16:16:29 +0800 Subject: [PATCH] [iOS] Slider animation can be forbidden on iOS which is the default behavior of Android. (#1849) --- .../Sources/Component/WXCycleSliderComponent.mm | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-) diff --git a/ios/sdk/WeexSDK/Sources/Component/WXCycleSliderComponent.mm b/ios/sdk/WeexSDK/Sources/Component/WXCycleSliderComponent.mm index 4fb0b91489..0bd71bc1b3 100644 --- a/ios/sdk/WeexSDK/Sources/Component/WXCycleSliderComponent.mm +++ b/ios/sdk/WeexSDK/Sources/Component/WXCycleSliderComponent.mm @@ -58,6 +58,7 @@ @interface WXRecycleSliderView : UIView @property (nonatomic, assign) CGRect currentItemFrame; @property (nonatomic, assign) CGRect nextItemFrame; @property (nonatomic, assign) BOOL infinite; +@property (nonatomic, assign) BOOL forbidSlideAnimation; - (void)insertItemView:(UIView *)view atIndex:(NSInteger)index; - (void)removeItemView:(UIView *)view; @@ -168,7 +169,7 @@ - (void)setCurrentIndex:(NSInteger)currentIndex } [self resetAllViewsFrame]; } else { - [_scrollView setContentOffset:CGPointMake(_currentIndex * self.width, 0) animated:YES]; + [_scrollView setContentOffset:CGPointMake(_currentIndex * self.width, 0) animated:!_forbidSlideAnimation]; } [self resetIndicatorPoint]; if (self.delegate && [self.delegate respondsToSelector:@selector(recycleSliderView:didScrollToItemAtIndex:)]) { @@ -248,12 +249,12 @@ - (void)resetAllViewsFrame - (void)nextPage { if (_itemViews.count > 1) { if (_infinite) { - [self.scrollView setContentOffset:CGPointMake(self.width * 2, 0) animated:YES]; + [self.scrollView setContentOffset:CGPointMake(self.width * 2, 0) animated:!_forbidSlideAnimation]; } else { // the currentindex will be set at the end of animation NSInteger nextIndex = self.currentIndex + 1; if(nextIndex < _itemViews.count) { - [self.scrollView setContentOffset:CGPointMake(nextIndex * self.width, 0) animated:YES]; + [self.scrollView setContentOffset:CGPointMake(nextIndex * self.width, 0) animated:!_forbidSlideAnimation]; } } } @@ -391,6 +392,7 @@ @interface WXCycleSliderComponent () setFlexDirection(WeexCore::kFlexDirectionRow,NO); } return self; @@ -446,6 +451,7 @@ - (void)viewDidLoad _recycleSliderView.exclusiveTouch = YES; _recycleSliderView.scrollView.scrollEnabled = _scrollable; _recycleSliderView.infinite = _infinite; + _recycleSliderView.forbidSlideAnimation = _forbidSlideAnimation; UIAccessibilityTraits traits = UIAccessibilityTraitAdjustable; if (_autoPlay) { traits |= UIAccessibilityTraitUpdatesFrequently; @@ -569,6 +575,11 @@ - (void)willRemoveSubview:(WXComponent *)component - (void)updateAttributes:(NSDictionary *)attributes { + if (attributes[@"forbidSlideAnimation"]) { + _forbidSlideAnimation = [WXConvert BOOL:attributes[@"forbidSlideAnimation"]]; + _recycleSliderView.forbidSlideAnimation = _forbidSlideAnimation; + } + if (attributes[@"autoPlay"]) { _autoPlay = [WXConvert BOOL:attributes[@"autoPlay"]]; if (_autoPlay) {