Android: Slider support slidePosition

This commit is contained in:
王劲鹏 2023-04-04 20:44:23 +08:00 committed by osborn
parent d80507a70f
commit 592bd3df53

View File

@ -54,6 +54,9 @@ public class SliderNode extends SuperNode<RecyclerView> {
private float minScale = 0.618f; private float minScale = 0.618f;
private float maxScale = 1; private float maxScale = 1;
private int slidePosition;
private boolean needSlideToPosition;
public SliderNode(DoricContext doricContext) { public SliderNode(DoricContext doricContext) {
super(doricContext); super(doricContext);
this.slideAdapter = new SlideAdapter(this); this.slideAdapter = new SlideAdapter(this);
@ -187,7 +190,8 @@ public class SliderNode extends SuperNode<RecyclerView> {
final boolean needToScroll = (loop && !slideAdapter.loop) final boolean needToScroll = (loop && !slideAdapter.loop)
|| (!renderPageFuncId.equals(slideAdapter.renderPageFuncId)) || (!renderPageFuncId.equals(slideAdapter.renderPageFuncId))
|| (slideAdapter.itemCount == 0 && itemCount > 0); || (slideAdapter.itemCount == 0 && itemCount > 0)
|| needSlideToPosition;
// If reset renderItem,should reset native cache. // If reset renderItem,should reset native cache.
if (!renderPageFuncId.equals(slideAdapter.renderPageFuncId)) { if (!renderPageFuncId.equals(slideAdapter.renderPageFuncId)) {
@ -209,8 +213,10 @@ public class SliderNode extends SuperNode<RecyclerView> {
mView.post(new Runnable() { mView.post(new Runnable() {
@Override @Override
public void run() { public void run() {
int position = slideAdapter.loop ? 1 : 0; int position = (slideAdapter.loop ? 1 : 0) + SliderNode.this.slidePosition;
mView.scrollToPosition(position); mView.scrollToPosition(position);
needSlideToPosition = false;
} }
}); });
} }
@ -253,6 +259,17 @@ public class SliderNode extends SuperNode<RecyclerView> {
this.minScale = prop.asObject().getProperty("minScale").asNumber().toFloat(); this.minScale = prop.asObject().getProperty("minScale").asNumber().toFloat();
} }
break; break;
case "slidePosition":
if (prop.isNumber()) {
int newSlidePosition = prop.asNumber().toInt();
if (this.slidePosition == newSlidePosition) {
} else {
needSlideToPosition = true;
}
this.slidePosition = newSlidePosition;
}
break;
default: default:
super.blend(view, name, prop); super.blend(view, name, prop);
break; break;
@ -319,6 +336,7 @@ public class SliderNode extends SuperNode<RecyclerView> {
slideStyle = null; slideStyle = null;
minScale = .618f; minScale = .618f;
maxScale = 1.f; maxScale = 1.f;
slidePosition = 0;
} }
private static class DoricLinearSmoothScroller extends LinearSmoothScroller { private static class DoricLinearSmoothScroller extends LinearSmoothScroller {