I am rewriting an app from XML to Android Compose. The legacy application uses ViewPager2 to sliding full screen cards.
Inside these cards are other gestures such as zooming or sliding elements vertically. To provide a better user experience, the sensitivity of sliding cards has been reduced. This allows to prioritize gestures within nested cards, without accidentally sliding.
In XML version is achieved with:
private void reduceDragSensitivity(int sensitivity) {
try {
Field touchSlopField = RecyclerView.class.getDeclaredField("mTouchSlop");
touchSlopField.setAccessible(true);
int touchSlop = (int) Objects.requireNonNull(touchSlopField.get(recyclerView));
touchSlopField.set(recyclerView, touchSlop * sensitivity);
} catch (NoSuchFieldException | IllegalAccessException e) {
throw new RuntimeException(e);
}
}
I can't achieve this with HorizontalPager in Android Compose:
val pagerState = rememberPagerState(pageCount = {10})
HorizontalPager(state = pagerState) { page ->
Card(
Modifier
.fillMaxWidth()
.fillMaxHeight()
) {
Text(
text = "Page: $page",
modifier = Modifier.fillMaxWidth()
)
}
}