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]; + } }); } }