'Is there a way to disable right horizontal scrolling on jetpack-compose accompanist horizontal pager?
I have a basic exam in my app which is user should give some answer. After user answered the question than I want to allow swipe to right of horizontal pager. My pager is like down below.
pagerState = rememberPagerState()
HorizontalPager(
modifier = Modifier.fillMaxSize(),
count = questionList.size,
state = pagerState) {
QuestionComponent(questionList[it], onUserAnswered = onUserAnswered) //Full Size Question
}
at the top, user can swipe both direction. But if user didn't answered the question user shouldn't swipe page to right. How can I prevent this?
Solution 1:[1]
You can pass only the available questions count to the pager, and increase this value when next question is answered.
val questions = List(10) { it.toString() }
var lastAvailableQuestion by remember { mutableStateOf(1) }
HorizontalPager(
lastAvailableQuestion
) { page ->
Text(questions[page])
Button({
// check if correct
lastAvailableQuestion += 1
}) {
Text("Check my answer")
}
if (page + 1 < lastAvailableQuestion) {
Button({
}) {
Text("Go to next question")
}
}
}
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | Pylyp Dukhov |
