fix wrong page slided index

This commit is contained in:
王劲鹏
2021-07-05 12:05:35 +08:00
committed by osborn
parent 84ca53c3b7
commit 666998d3a6
3 changed files with 143 additions and 9 deletions

View File

@@ -81,8 +81,14 @@ public class SliderNode extends SuperNode<RecyclerView> {
if (slideAdapter.loop) {
if (position == 0) {
recyclerView.scrollToPosition(slideAdapter.itemCount);
position = slideAdapter.itemCount - 1;
} else if (position == slideAdapter.itemCount + 1) {
recyclerView.scrollToPosition(1);
position = 0;
} else {
position = position - 1;
}
}
@@ -202,9 +208,18 @@ public class SliderNode extends SuperNode<RecyclerView> {
int page = params.getProperty("page").asNumber().toInt();
boolean smooth = params.getProperty("smooth").asBoolean().value();
if (smooth) {
mView.smoothScrollToPosition(page);
if (slideAdapter.loop) {
mView.smoothScrollToPosition(page + 1);
} else {
mView.smoothScrollToPosition(page);
}
} else {
mView.scrollToPosition(page);
if (slideAdapter.loop) {
mView.scrollToPosition(page + 1);
} else {
mView.scrollToPosition(page);
}
}
if (!TextUtils.isEmpty(onPageSlidedFuncId)) {
callJSResponse(onPageSlidedFuncId, page);
@@ -216,6 +231,11 @@ public class SliderNode extends SuperNode<RecyclerView> {
@DoricMethod
public int getSlidedPage() {
LinearLayoutManager linearLayoutManager = (LinearLayoutManager) mView.getLayoutManager();
return linearLayoutManager != null ? linearLayoutManager.findFirstVisibleItemPosition() : 0;
int pageIndex = linearLayoutManager != null ? linearLayoutManager.findFirstVisibleItemPosition() : 0;
if (slideAdapter.loop) {
return pageIndex - 1;
} else {
return pageIndex;
}
}
}