From f8a5e29c83ae3d3c7c7505f81b4ba94553c43e45 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=8E=8B=E5=8A=B2=E9=B9=8F?= Date: Fri, 10 Apr 2020 11:06:36 +0800 Subject: [PATCH] iOS: add loop in slider --- .../Pod/Classes/Shader/DoricSliderNode.m | 41 +++++++++++++++++-- 1 file changed, 37 insertions(+), 4 deletions(-) diff --git a/doric-iOS/Pod/Classes/Shader/DoricSliderNode.m b/doric-iOS/Pod/Classes/Shader/DoricSliderNode.m index d31d2cf07..10387d839 100644 --- a/doric-iOS/Pod/Classes/Shader/DoricSliderNode.m +++ b/doric-iOS/Pod/Classes/Shader/DoricSliderNode.m @@ -36,6 +36,7 @@ @interface DoricSliderNode () 0) { return [self subModelOf:viewId]; } else { - DoricAsyncResult *result = [self callJSResponse:@"renderBunchedItems", @(position), @(self.batchCount), nil]; + DoricAsyncResult *result = [self callJSResponse:@"renderBunchedItems", @(index), @(self.batchCount), nil]; JSValue *models = [result waitUntilResult]; NSArray *array = [models toArray]; [array enumerateObjectsUsingBlock:^(NSDictionary *obj, NSUInteger idx, BOOL *stop) { NSString *thisViewId = obj[@"id"]; [self setSubModel:obj in:thisViewId]; - NSUInteger pos = position + idx; + NSUInteger pos = index + idx; self.itemViewIds[@(pos)] = thisViewId; }]; return array[0]; @@ -191,6 +215,15 @@ - (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.loop) { + if (pageIndex == 0) { + [self.view setContentOffset:CGPointMake(self.itemCount * self.view.width, self.view.contentOffset.y) animated:false]; + } else if (pageIndex == self.itemCount + 1) { + [self.view setContentOffset:CGPointMake(1 * self.view.width, self.view.contentOffset.y) animated:false]; + } + } + if (self.onPageSelectedFuncId && self.onPageSelectedFuncId.length > 0) { if (pageIndex != self.lastPosition) { [self callJSResponse:self.onPageSelectedFuncId, @(pageIndex), nil];