From 7c5ac7b5b208825deafc890bf72988035dcfecad Mon Sep 17 00:00:00 2001 From: "pengfei.zhou" Date: Fri, 6 Dec 2019 15:46:51 +0800 Subject: [PATCH] feat:add slider control events --- Pod/Classes/Shader/DoricSliderNode.m | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) diff --git a/Pod/Classes/Shader/DoricSliderNode.m b/Pod/Classes/Shader/DoricSliderNode.m index 899b88f8..32e8b96f 100644 --- a/Pod/Classes/Shader/DoricSliderNode.m +++ b/Pod/Classes/Shader/DoricSliderNode.m @@ -35,6 +35,7 @@ @interface DoricSliderNode () *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