feat:add slider control events
This commit is contained in:
parent
7218ec3d1b
commit
7c5ac7b5b2
@ -35,6 +35,7 @@ @interface DoricSliderNode () <UICollectionViewDataSource, UICollectionViewDeleg
|
||||
@property(nonatomic, strong) NSMutableDictionary <NSNumber *, NSString *> *itemViewIds;
|
||||
@property(nonatomic, assign) NSUInteger itemCount;
|
||||
@property(nonatomic, assign) NSUInteger batchCount;
|
||||
@property(nonatomic, copy) NSString *onPageSelectedFuncId;
|
||||
@end
|
||||
|
||||
@interface DoricSliderView : UICollectionView
|
||||
@ -95,6 +96,8 @@ - (void)blendView:(UICollectionView *)view forPropName:(NSString *)name propValu
|
||||
[self.view reloadData];
|
||||
} else if ([@"batchCount" isEqualToString:name]) {
|
||||
self.batchCount = [prop unsignedIntegerValue];
|
||||
} else if ([@"onPageSlided" isEqualToString:name]) {
|
||||
self.onPageSelectedFuncId = prop;
|
||||
} else {
|
||||
[super blendView:view forPropName:name propValue:prop];
|
||||
}
|
||||
@ -197,5 +200,29 @@ - (void)blendSubNode:(NSDictionary *)subModel {
|
||||
- (void)scrollViewDidEndDecelerating:(UIScrollView *)scrollView {
|
||||
NSUInteger pageIndex = (NSUInteger) (scrollView.contentOffset.x / scrollView.width);
|
||||
scrollView.contentOffset = CGPointMake(pageIndex * scrollView.width, scrollView.contentOffset.y);
|
||||
if (self.onPageSelectedFuncId && self.onPageSelectedFuncId.length > 0) {
|
||||
[self callJSResponse:self.onPageSelectedFuncId, @(pageIndex), nil];
|
||||
}
|
||||
}
|
||||
|
||||
- (void)slidePage:(NSDictionary *)params withPromise:(DoricPromise *)promise {
|
||||
NSUInteger pageIndex = [params[@"page"] unsignedIntegerValue];
|
||||
BOOL smooth = [params[@"smooth"] boolValue];
|
||||
if (smooth) {
|
||||
[UIView animateWithDuration:.3f animations:^{
|
||||
self.view.contentOffset = CGPointMake(pageIndex * self.view.width, self.view.contentOffset.y);
|
||||
}
|
||||
completion:^(BOOL finished) {
|
||||
[promise resolve:nil];
|
||||
}];
|
||||
} else {
|
||||
self.view.contentOffset = CGPointMake(pageIndex * self.view.width, self.view.contentOffset.y);
|
||||
}
|
||||
}
|
||||
|
||||
- (NSNumber *)getSlidedPage {
|
||||
NSUInteger pageIndex = (NSUInteger) (self.view.contentOffset.x / self.view.width);
|
||||
return @(pageIndex);
|
||||
}
|
||||
|
||||
@end
|
||||
|
Reference in New Issue
Block a user