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

Commit fe6f8c9

Browse files
wqyfavorcxfeng1
authored andcommitted
[iOS] Slider animation can be forbidden on iOS which is the default behavior of Android. (#1849)
1 parent d16cf17 commit fe6f8c9

File tree

1 file changed

+14
-3
lines changed

1 file changed

+14
-3
lines changed

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

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,7 @@ @interface WXRecycleSliderView : UIView <UIScrollViewDelegate>
5858
@property (nonatomic, assign) CGRect currentItemFrame;
5959
@property (nonatomic, assign) CGRect nextItemFrame;
6060
@property (nonatomic, assign) BOOL infinite;
61+
@property (nonatomic, assign) BOOL forbidSlideAnimation;
6162

6263
- (void)insertItemView:(UIView *)view atIndex:(NSInteger)index;
6364
- (void)removeItemView:(UIView *)view;
@@ -168,7 +169,7 @@ - (void)setCurrentIndex:(NSInteger)currentIndex
168169
}
169170
[self resetAllViewsFrame];
170171
} else {
171-
[_scrollView setContentOffset:CGPointMake(_currentIndex * self.width, 0) animated:YES];
172+
[_scrollView setContentOffset:CGPointMake(_currentIndex * self.width, 0) animated:!_forbidSlideAnimation];
172173
}
173174
[self resetIndicatorPoint];
174175
if (self.delegate && [self.delegate respondsToSelector:@selector(recycleSliderView:didScrollToItemAtIndex:)]) {
@@ -248,12 +249,12 @@ - (void)resetAllViewsFrame
248249
- (void)nextPage {
249250
if (_itemViews.count > 1) {
250251
if (_infinite) {
251-
[self.scrollView setContentOffset:CGPointMake(self.width * 2, 0) animated:YES];
252+
[self.scrollView setContentOffset:CGPointMake(self.width * 2, 0) animated:!_forbidSlideAnimation];
252253
} else {
253254
// the currentindex will be set at the end of animation
254255
NSInteger nextIndex = self.currentIndex + 1;
255256
if(nextIndex < _itemViews.count) {
256-
[self.scrollView setContentOffset:CGPointMake(nextIndex * self.width, 0) animated:YES];
257+
[self.scrollView setContentOffset:CGPointMake(nextIndex * self.width, 0) animated:!_forbidSlideAnimation];
257258
}
258259
}
259260
}
@@ -391,6 +392,7 @@ @interface WXCycleSliderComponent () <WXRecycleSliderViewDelegate,WXIndicatorCom
391392
@property (nonatomic, strong) NSMutableArray *childrenView;
392393
@property (nonatomic, assign) BOOL scrollable;
393394
@property (nonatomic, assign) BOOL infinite;
395+
@property (nonatomic, assign) BOOL forbidSlideAnimation;
394396

395397
@end
396398

@@ -426,6 +428,9 @@ - (instancetype)initWithRef:(NSString *)ref type:(NSString *)type styles:(NSDict
426428
_offsetXAccuracy = [WXConvert CGFloat:attributes[@"offsetXAccuracy"]];
427429
}
428430
_infinite = attributes[@"infinite"] ? [WXConvert BOOL:attributes[@"infinite"]] : YES;
431+
432+
_forbidSlideAnimation = attributes[@"forbidSlideAnimation"] ? [WXConvert BOOL:attributes[@"forbidSlideAnimation"]] : NO;
433+
429434
self.flexCssNode->setFlexDirection(WeexCore::kFlexDirectionRow,NO);
430435
}
431436
return self;
@@ -446,6 +451,7 @@ - (void)viewDidLoad
446451
_recycleSliderView.exclusiveTouch = YES;
447452
_recycleSliderView.scrollView.scrollEnabled = _scrollable;
448453
_recycleSliderView.infinite = _infinite;
454+
_recycleSliderView.forbidSlideAnimation = _forbidSlideAnimation;
449455
UIAccessibilityTraits traits = UIAccessibilityTraitAdjustable;
450456
if (_autoPlay) {
451457
traits |= UIAccessibilityTraitUpdatesFrequently;
@@ -569,6 +575,11 @@ - (void)willRemoveSubview:(WXComponent *)component
569575

570576
- (void)updateAttributes:(NSDictionary *)attributes
571577
{
578+
if (attributes[@"forbidSlideAnimation"]) {
579+
_forbidSlideAnimation = [WXConvert BOOL:attributes[@"forbidSlideAnimation"]];
580+
_recycleSliderView.forbidSlideAnimation = _forbidSlideAnimation;
581+
}
582+
572583
if (attributes[@"autoPlay"]) {
573584
_autoPlay = [WXConvert BOOL:attributes[@"autoPlay"]];
574585
if (_autoPlay) {

0 commit comments

Comments
 (0)