Skip to content

Commit

Permalink
* [ios] fix slider-neighbor
Browse files Browse the repository at this point in the history
  • Loading branch information
acton393 committed Sep 8, 2016
1 parent 353eecc commit bc03620
Showing 1 changed file with 25 additions and 27 deletions.
52 changes: 25 additions & 27 deletions ios/sdk/WeexSDK/Sources/Component/WXSliderNeighborComponent.m
Original file line number Diff line number Diff line change
Expand Up @@ -674,7 +674,7 @@ - (NSInteger)lastItemIndex
if ([self currentItemIndex] == 0) {
return _numberOfItems - 1;
}
return ((NSInteger)round(fabs([self currentItemIndex] -1))) % _numberOfItems;
return ((NSInteger)round(abs((int)[self currentItemIndex] - 1))) % _numberOfItems;
}

- (NSInteger)minScrollDistanceFromIndex:(NSInteger)fromIndex toIndex:(NSInteger)toIndex
Expand Down Expand Up @@ -1367,7 +1367,6 @@ - (CGFloat)sliderNeighbor:(__unused WXSliderNeighborView *)sliderNeighbor

@end

typedef void (^WXSliderNeighborRestore)();
@interface WXSliderNeighborComponent() {
WXPixelType neighborSpace;
CGFloat neighborAlpha;
Expand All @@ -1381,7 +1380,7 @@ @interface WXSliderNeighborComponent() {
@property (nonatomic, strong) NSTimer *autoTimer;
@property (nonatomic, assign) BOOL sliderChangeEvent;
@property (nonatomic, assign) NSInteger currentIndex;
@property (nonatomic) WXSliderNeighborRestore restore;
@property (nonatomic) CGRect itemRect;
@end

@implementation WXSliderNeighborComponent
Expand All @@ -1397,7 +1396,8 @@ - (instancetype)initWithRef:(NSString *)ref type:(NSString *)type styles:(NSDict
[self setNeighborAlpha:attributes];
[self setNeighborScale:attributes];
_items = [NSMutableArray array];

_itemRect = CGRectNull;

if (attributes[@"autoPlay"]) {
_autoPlay = [attributes[@"autoPlay"] boolValue];
}
Expand Down Expand Up @@ -1652,8 +1652,11 @@ - (UIView *)sliderNeighbor:(WXSliderNeighborView *)sliderNeighbor viewForItemAtI
view.tag = 1;
}
//
if (CGRectIsNull(_itemRect)) {
_itemRect = view.frame;
}
CGAffineTransform transfrom = CGAffineTransformIdentity;
transfrom = CGAffineTransformMakeScale(1-self->neighborSpace*2/view.frame.size.width, 1.0);
transfrom = CGAffineTransformMakeScale(1-self->neighborSpace*2/_itemRect.size.width, 1.0);

if (index != [self.sliderView currentItemIndex]) {
transfrom = CGAffineTransformConcat(transfrom, CGAffineTransformMakeScale(self->neighborScale, self->neighborScale));
Expand Down Expand Up @@ -1705,30 +1708,25 @@ - (void)sliderNeighborDidEndDragging:(WXSliderNeighborView *)sliderNeighbor will
if (_autoPlay) {
[self _startAutoPlayTimer];
}
}

- (void)sliderNeighborDidEndScrollingAnimation:(WXSliderNeighborView *)sliderNeighbor {

}

- (void)sliderNeighborCurrentItemIndexDidChange:(WXSliderNeighborView *)sliderNeighbor from:(NSInteger)from to:(NSInteger)to
{
UIView * currentView = [sliderNeighbor itemViewAtIndex:[sliderNeighbor currentItemIndex]];
UIView * lastView = [sliderNeighbor itemViewAtIndex:[sliderNeighbor lastItemIndex]];

[UIView animateWithDuration:0.2 animations:^{
CGAffineTransform transfrom = CGAffineTransformIdentity;
currentView.alpha = 1.0;
currentView.transform = transfrom;
lastView.transform = transfrom;

transfrom = CGAffineTransformConcat(transfrom,CGAffineTransformMakeScale(1-self->neighborSpace*2/currentView.frame.size.width, 1.0));
currentView.transform = transfrom;

transfrom = CGAffineTransformConcat(transfrom, CGAffineTransformMakeScale(self->neighborScale, self->neighborScale));
lastView.alpha = self->neighborAlpha;
lastView.transform = transfrom;

UIView * nextView = [sliderNeighbor itemViewAtIndex:[sliderNeighbor nextItemIndex]];
__block CGAffineTransform transfrom = CGAffineTransformIdentity;
__weak typeof(self) weakSelf = self;
[UIView animateWithDuration:0.4 animations:^{
__strong typeof(self) strongSelf = weakSelf;
if (strongSelf) {
currentView.alpha = 1.0;

transfrom = CGAffineTransformConcat(transfrom,CGAffineTransformMakeScale(1-strongSelf->neighborSpace*2/_itemRect.size.width, 1.0));
currentView.transform = transfrom;

transfrom = CGAffineTransformConcat(transfrom, CGAffineTransformMakeScale(strongSelf->neighborScale, strongSelf->neighborScale));
lastView.alpha = strongSelf->neighborAlpha;
lastView.transform = transfrom;
nextView.alpha = strongSelf->neighborAlpha;
nextView.transform = transfrom;
}
}];
}

Expand Down

0 comments on commit bc03620

Please sign in to comment.