fix some problems of AppControlDialog

use state to control SwitchItem
This commit is contained in:
BinTianqi
2024-08-13 16:11:54 +08:00
parent 3d000358c4
commit b452005ada
15 changed files with 149 additions and 126 deletions

View File

@@ -124,6 +124,7 @@ fun CheckBoxItem(
}
}
@Composable
fun SwitchItem(
@StringRes title: Int,
@@ -135,7 +136,21 @@ fun SwitchItem(
onClickBlank: (() -> Unit)? = null,
padding: Boolean = true
) {
var checked by remember { mutableStateOf(getState()) }
var state by remember { mutableStateOf(getState()) }
SwitchItem(title, desc, icon, state, { onCheckedChange(it); state = getState() }, enable, onClickBlank, padding)
}
@Composable
fun SwitchItem(
@StringRes title: Int,
desc: String,
@DrawableRes icon: Int?,
state: Boolean,
onCheckedChange: (Boolean)->Unit,
enable: Boolean = true,
onClickBlank: (() -> Unit)? = null,
padding: Boolean = true
) {
Box(
modifier = Modifier
.fillMaxWidth()
@@ -159,7 +174,7 @@ fun SwitchItem(
}
}
Switch(
checked = checked, onCheckedChange = { onCheckedChange(it); checked = getState() },
checked = state, onCheckedChange = { onCheckedChange(it) },
modifier = Modifier.align(Alignment.CenterEnd), enabled = enable
)
}