Android: fix inaccurate scroll when slider in gallery style
This commit is contained in:
parent
1b105d70e4
commit
722d0873d4
@ -60,6 +60,8 @@ public class SliderNode extends SuperNode<RecyclerView> {
|
||||
private int slidePosition;
|
||||
private boolean needSlideToPosition;
|
||||
|
||||
private PagerSnapHelper snapHelper;
|
||||
|
||||
public SliderNode(DoricContext doricContext) {
|
||||
super(doricContext);
|
||||
this.slideAdapter = new SlideAdapter(this);
|
||||
@ -69,7 +71,6 @@ public class SliderNode extends SuperNode<RecyclerView> {
|
||||
protected RecyclerView build() {
|
||||
final RecyclerView recyclerView = new RecyclerView(getContext());
|
||||
|
||||
|
||||
final SliderLayoutManager layoutManager = new SliderLayoutManager(getContext(), LinearLayoutManager.HORIZONTAL, false) {
|
||||
@Override
|
||||
public boolean canScrollHorizontally() {
|
||||
@ -92,7 +93,7 @@ public class SliderNode extends SuperNode<RecyclerView> {
|
||||
};
|
||||
|
||||
recyclerView.setLayoutManager(layoutManager);
|
||||
final PagerSnapHelper snapHelper = new PagerSnapHelper();
|
||||
snapHelper = new PagerSnapHelper();
|
||||
snapHelper.attachToRecyclerView(recyclerView);
|
||||
|
||||
recyclerView.addItemDecoration(new RecyclerView.ItemDecoration() {
|
||||
@ -332,6 +333,20 @@ public class SliderNode extends SuperNode<RecyclerView> {
|
||||
} else {
|
||||
mView.scrollToPosition(page);
|
||||
}
|
||||
|
||||
if (slideStyle.equals("gallery")) {
|
||||
mView.post(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
View snapView = snapHelper.findSnapView(mView.getLayoutManager());
|
||||
if (snapView != null) {
|
||||
int[] distance = snapHelper.calculateDistanceToFinalSnap(mView.getLayoutManager(), snapView);
|
||||
mView.smoothScrollBy(distance[0], distance[1]);
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
}
|
||||
if (!TextUtils.isEmpty(onPageSlidedFuncId)) {
|
||||
callJSResponse(onPageSlidedFuncId, page);
|
||||
|
@ -33,5 +33,9 @@ class SliderStyleDemo extends Panel {
|
||||
heightSpec: LayoutSpec.MOST,
|
||||
}
|
||||
}))
|
||||
|
||||
setTimeout(() => {
|
||||
pager.slidePage(this.context, 2, false);
|
||||
}, 200)
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user