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

Commit

Permalink
[iOS] Slider animation can be forbidden on iOS which is the default b…
Browse files Browse the repository at this point in the history
…ehavior of Android. (#1849)
  • Loading branch information
wqyfavor authored and cxfeng1 committed Nov 30, 2018
1 parent d16cf17 commit fe6f8c9
Showing 1 changed file with 14 additions and 3 deletions.
17 changes: 14 additions & 3 deletions ios/sdk/WeexSDK/Sources/Component/WXCycleSliderComponent.mm
Expand Up @@ -58,6 +58,7 @@ @interface WXRecycleSliderView : UIView <UIScrollViewDelegate>
@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;
Expand Down Expand Up @@ -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:)]) {
Expand Down Expand Up @@ -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];
}
}
}
Expand Down Expand Up @@ -391,6 +392,7 @@ @interface WXCycleSliderComponent () <WXRecycleSliderViewDelegate,WXIndicatorCom
@property (nonatomic, strong) NSMutableArray *childrenView;
@property (nonatomic, assign) BOOL scrollable;
@property (nonatomic, assign) BOOL infinite;
@property (nonatomic, assign) BOOL forbidSlideAnimation;

@end

Expand Down Expand Up @@ -426,6 +428,9 @@ - (instancetype)initWithRef:(NSString *)ref type:(NSString *)type styles:(NSDict
_offsetXAccuracy = [WXConvert CGFloat:attributes[@"offsetXAccuracy"]];
}
_infinite = attributes[@"infinite"] ? [WXConvert BOOL:attributes[@"infinite"]] : YES;

_forbidSlideAnimation = attributes[@"forbidSlideAnimation"] ? [WXConvert BOOL:attributes[@"forbidSlideAnimation"]] : NO;

self.flexCssNode->setFlexDirection(WeexCore::kFlexDirectionRow,NO);
}
return self;
Expand All @@ -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;
Expand Down Expand Up @@ -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) {
Expand Down

0 comments on commit fe6f8c9

Please sign in to comment.