我有下一个代码,一切都很好,除了我需要把我的第二个AnswerOption
放在一个lazyverticalGrid中。我不能这样做,因为它在一个lazycolumn中,这是代码
@Composable
fun AssessmentScreen(
onClose: (String, String) -> Unit,
relatedSubSkillIdsJson: String,
uiState: AssessmentUiState,
onSelectedOption: (String) -> Unit,
onShowAnswerFeedback: (Boolean) -> Unit,
onNextQuestion: () -> Unit,
onCloseAssessment: () -> Unit,
navigateToAndPop: (Pair<String, String>) -> Unit,
goBack: () -> Unit,
assessmentType: String,
) {
val context = LocalContext.current
val activity = context.findActivity()
val navigationBarHeightDp = activity?.getNavigationBarHeightInDp() ?: 0.dp
val blur =
if (uiState.isLoading) dimensionResource(dimen.default_screen_blur) else 0.dp
val currentArtiIndex = remember { mutableStateOf(0) }
if (uiState.questions.isNotEmpty()) {
LazyColumn(
Modifier
.fillMaxSize()
.padding(
top = dimensionResource(dimen.default_screen_padding),
start = dimensionResource(dimen.default_screen_padding),
end = dimensionResource(dimen.default_screen_padding)
)
.blur(blur)
) {
item {
CloseAssessment(
relatedSubSkillIdsJson = relatedSubSkillIdsJson,
uiState = uiState,
questionIndex = uiState.currentQuestionIndex,
isAnsweredQuestion = uiState.showAnswerFeedback,
onCloseAssessment = { onCloseAssessment() },
navigateToAndPop = navigateToAndPop,
goBack = goBack
)
AssessmentTitle(artiImages[currentArtiIndex.value], assessmentType)
QuestionDotsIndicator(uiState.questionAnswersStatus)
AssessmentQuestion(
thumbnail = uiState.getCurrentQuestionItem().thumbnail,
question = uiState.getCurrentQuestionItem().question
)
Spacer(modifier = Modifier.height(20.dp))
}
val optionsAbcLetterDescription = ('a'..'z').toList()
itemsIndexed(uiState.currentAnswerOptions) { index, option ->
if (uiState.currentAnswerOptions[index].thumbnail == ""){
AnswerOption(
selectedOptionId = uiState.selectedAnswerId,
showFeedback = uiState.showAnswerFeedback,
optionLetter = circularCharIteration(optionsAbcLetterDescription, index),
option = option,
onSelectedOption = { onSelectedOption(it) }
)
}else{
AnswerOption(
selectedOptionId = uiState.selectedAnswerId,
showFeedback = uiState.showAnswerFeedback,
optionLetter = circularCharIteration(optionsAbcLetterDescription, index),
option = option,
onSelectedOption = { onSelectedOption(it) }
)
}
}
item {
ChallengeBtn(
modifier = Modifier
.padding(bottom = navigationBarHeightDp + dimensionResource(dimen.default_screen_padding)),
uiState = uiState,
navigateToAndPop = navigateToAndPop,
onShowAnswerFeedback = { onShowAnswerFeedback(it) },
onCloseAssessment = { onCloseAssessment() },
onNextQuestion = {
if (!uiState.isLastQuestion) {
currentArtiIndex.value =
nextArtiImage(currentArtiIndex.value)
onNextQuestion()
}
} ,
relatedSubSkillIdsJson = relatedSubSkillIdsJson,
)
}
}
}
ProgressBarComponentComposable(isLoading = uiState.isLoading)
你知道怎么做吗?
1条答案
按热度按时间a11xaf1n1#
将其 Package 在
item{…}
块内也可以将
AnswerOption
作为LazyItemScope
的扩展,你可以这样简单地调用它