From 187dd9e0c376ac1ba62fda7daf9ac4d46cd8a7cb Mon Sep 17 00:00:00 2001 From: "pengfei.zhou" Date: Fri, 6 Dec 2019 16:34:20 +0800 Subject: [PATCH] feat:iOS add Slider event --- Pod/Classes/Shader/DoricSliderNode.m | 21 +++++++++++---------- 1 file changed, 11 insertions(+), 10 deletions(-) diff --git a/Pod/Classes/Shader/DoricSliderNode.m b/Pod/Classes/Shader/DoricSliderNode.m index 32e8b96f..23038297 100644 --- a/Pod/Classes/Shader/DoricSliderNode.m +++ b/Pod/Classes/Shader/DoricSliderNode.m @@ -36,6 +36,7 @@ @interface DoricSliderNode () 0) { - [self callJSResponse:self.onPageSelectedFuncId, @(pageIndex), nil]; + if (pageIndex != self.lastPosition) { + [self callJSResponse:self.onPageSelectedFuncId, @(pageIndex), nil]; + } else { + self.lastPosition = pageIndex; + } } } - (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); + [self.view setContentOffset:CGPointMake(pageIndex * self.view.width, self.view.contentOffset.y) animated:smooth]; + [promise resolve:nil]; + self.lastPosition = pageIndex; + if (self.onPageSelectedFuncId && self.onPageSelectedFuncId.length > 0) { + [self callJSResponse:self.onPageSelectedFuncId, @(pageIndex), nil]; } }