fix: 无障碍描述类型错误
This commit is contained in:
parent
ddc1771da1
commit
c4a7930cfd
1 changed files with 14 additions and 13 deletions
|
|
@ -10,9 +10,10 @@ import androidx.compose.material3.Text
|
|||
import androidx.compose.runtime.Composable
|
||||
import androidx.compose.ui.Alignment
|
||||
import androidx.compose.ui.Modifier
|
||||
import androidx.compose.ui.platform.LocalContext
|
||||
import androidx.compose.ui.res.stringResource
|
||||
import androidx.compose.ui.semantics.clearAndSetSemantics
|
||||
import androidx.compose.ui.semantics.stateDescription
|
||||
import androidx.compose.ui.semantics.contentDescription
|
||||
import androidx.compose.ui.text.font.FontWeight
|
||||
import androidx.compose.ui.unit.dp
|
||||
import cn.super12138.todo.R
|
||||
|
|
@ -24,6 +25,8 @@ fun ProgressFragment(
|
|||
completedTasks: Int,
|
||||
modifier: Modifier = Modifier
|
||||
) {
|
||||
val context = LocalContext.current
|
||||
|
||||
val remainTasks = totalTasks - completedTasks
|
||||
val progress = if (totalTasks != 0) {
|
||||
completedTasks / totalTasks.toFloat()
|
||||
|
|
@ -32,17 +35,6 @@ fun ProgressFragment(
|
|||
0f
|
||||
}
|
||||
|
||||
val progressDescription = if (totalTasks != 0) {
|
||||
stringResource(
|
||||
R.string.accessibility_progress_tasks,
|
||||
totalTasks,
|
||||
completedTasks,
|
||||
remainTasks
|
||||
)
|
||||
} else {
|
||||
stringResource(R.string.accessibility_progress_no_tasks)
|
||||
}
|
||||
|
||||
Box(
|
||||
modifier = modifier,
|
||||
contentAlignment = Alignment.Center
|
||||
|
|
@ -60,7 +52,16 @@ fun ProgressFragment(
|
|||
Row(
|
||||
verticalAlignment = Alignment.CenterVertically,
|
||||
modifier = Modifier.clearAndSetSemantics {
|
||||
stateDescription = progressDescription
|
||||
contentDescription = if (totalTasks != 0) {
|
||||
context.getString(
|
||||
R.string.accessibility_progress_tasks,
|
||||
totalTasks,
|
||||
completedTasks,
|
||||
remainTasks
|
||||
)
|
||||
} else {
|
||||
context.getString(R.string.accessibility_progress_no_tasks)
|
||||
}
|
||||
}
|
||||
) {
|
||||
Text(
|
||||
|
|
|
|||
Loading…
Reference in a new issue