From 4cfb7b4076c4425f4670edeece3bd888cf62e575 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=8E=8B=E5=8A=B2=E9=B9=8F?= Date: Mon, 20 Jun 2022 18:52:35 +0800 Subject: [PATCH] bugfix: slider need scroll logic --- .../pub/doric/shader/slider/SliderNode.java | 3 ++- doric-iOS/Pod/Classes/Shader/DoricSliderNode.m | 18 ++++++++++++++---- 2 files changed, 16 insertions(+), 5 deletions(-) diff --git a/doric-android/doric/src/main/java/pub/doric/shader/slider/SliderNode.java b/doric-android/doric/src/main/java/pub/doric/shader/slider/SliderNode.java index 7dfe6053..a20502c8 100644 --- a/doric-android/doric/src/main/java/pub/doric/shader/slider/SliderNode.java +++ b/doric-android/doric/src/main/java/pub/doric/shader/slider/SliderNode.java @@ -173,7 +173,8 @@ public class SliderNode extends SuperNode { mView.post(new Runnable() { @Override public void run() { - mView.scrollToPosition(1); + int position = slideAdapter.loop ? 1 : 0; + mView.scrollToPosition(position); } }); } diff --git a/doric-iOS/Pod/Classes/Shader/DoricSliderNode.m b/doric-iOS/Pod/Classes/Shader/DoricSliderNode.m index 58f99c1f..316161be 100644 --- a/doric-iOS/Pod/Classes/Shader/DoricSliderNode.m +++ b/doric-iOS/Pod/Classes/Shader/DoricSliderNode.m @@ -37,11 +37,12 @@ @interface DoricSliderNode () 0); + || (self.itemCount == 0 && self.propItemCount > 0) + || self.needResetScroll; // handle item count if (self.itemCount != self.propItemCount) { @@ -121,6 +123,7 @@ - (void)afterBlended:(NSDictionary *)props { // handle loop self.loop = self.propLoop; + __weak typeof(self) _self = self; if (needToScroll) { @@ -128,7 +131,14 @@ - (void)afterBlended:(NSDictionary *)props { __strong typeof(_self) self = _self; [self.view reloadData]; - [self.view setContentOffset:CGPointMake(1 * self.view.width, self.view.contentOffset.y) animated:false]; + + int position = self.loop ? 1 : 0; + if (self.view.width == 0) { + self.needResetScroll = true; + } else { + self.needResetScroll = false; + [self.view setContentOffset:CGPointMake(position * self.view.width, self.view.contentOffset.y) animated:false]; + } }); } }