feat:iOS add Slider event
This commit is contained in:
parent
7c5ac7b5b2
commit
187dd9e0c3
@ -36,6 +36,7 @@ @interface DoricSliderNode () <UICollectionViewDataSource, UICollectionViewDeleg
|
|||||||
@property(nonatomic, assign) NSUInteger itemCount;
|
@property(nonatomic, assign) NSUInteger itemCount;
|
||||||
@property(nonatomic, assign) NSUInteger batchCount;
|
@property(nonatomic, assign) NSUInteger batchCount;
|
||||||
@property(nonatomic, copy) NSString *onPageSelectedFuncId;
|
@property(nonatomic, copy) NSString *onPageSelectedFuncId;
|
||||||
|
@property(nonatomic, assign) NSUInteger lastPosition;
|
||||||
@end
|
@end
|
||||||
|
|
||||||
@interface DoricSliderView : UICollectionView
|
@interface DoricSliderView : UICollectionView
|
||||||
@ -201,22 +202,22 @@ - (void)scrollViewDidEndDecelerating:(UIScrollView *)scrollView {
|
|||||||
NSUInteger pageIndex = (NSUInteger) (scrollView.contentOffset.x / scrollView.width);
|
NSUInteger pageIndex = (NSUInteger) (scrollView.contentOffset.x / scrollView.width);
|
||||||
scrollView.contentOffset = CGPointMake(pageIndex * scrollView.width, scrollView.contentOffset.y);
|
scrollView.contentOffset = CGPointMake(pageIndex * scrollView.width, scrollView.contentOffset.y);
|
||||||
if (self.onPageSelectedFuncId && self.onPageSelectedFuncId.length > 0) {
|
if (self.onPageSelectedFuncId && self.onPageSelectedFuncId.length > 0) {
|
||||||
|
if (pageIndex != self.lastPosition) {
|
||||||
[self callJSResponse:self.onPageSelectedFuncId, @(pageIndex), nil];
|
[self callJSResponse:self.onPageSelectedFuncId, @(pageIndex), nil];
|
||||||
|
} else {
|
||||||
|
self.lastPosition = pageIndex;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
- (void)slidePage:(NSDictionary *)params withPromise:(DoricPromise *)promise {
|
- (void)slidePage:(NSDictionary *)params withPromise:(DoricPromise *)promise {
|
||||||
NSUInteger pageIndex = [params[@"page"] unsignedIntegerValue];
|
NSUInteger pageIndex = [params[@"page"] unsignedIntegerValue];
|
||||||
BOOL smooth = [params[@"smooth"] boolValue];
|
BOOL smooth = [params[@"smooth"] boolValue];
|
||||||
if (smooth) {
|
[self.view setContentOffset:CGPointMake(pageIndex * self.view.width, self.view.contentOffset.y) animated:smooth];
|
||||||
[UIView animateWithDuration:.3f animations:^{
|
|
||||||
self.view.contentOffset = CGPointMake(pageIndex * self.view.width, self.view.contentOffset.y);
|
|
||||||
}
|
|
||||||
completion:^(BOOL finished) {
|
|
||||||
[promise resolve:nil];
|
[promise resolve:nil];
|
||||||
}];
|
self.lastPosition = pageIndex;
|
||||||
} else {
|
if (self.onPageSelectedFuncId && self.onPageSelectedFuncId.length > 0) {
|
||||||
self.view.contentOffset = CGPointMake(pageIndex * self.view.width, self.view.contentOffset.y);
|
[self callJSResponse:self.onPageSelectedFuncId, @(pageIndex), nil];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user