Skip to content

Instantly share code, notes, and snippets.

@navczydev
Created October 30, 2022 01:04
Show Gist options
  • Save navczydev/d91b35c7d8f4377b86fe21ba3cdbcc55 to your computer and use it in GitHub Desktop.
Save navczydev/d91b35c7d8f4377b86fe21ba3cdbcc55 to your computer and use it in GitHub Desktop.
AndroidView(factory = { context ->
MaterialCheckBox(context).apply {
text = "Checkbox from 1.7"
addOnCheckedStateChangedListener { checkBox, state ->
when (state) {
STATE_INDETERMINATE -> {
stateValue.value = STATE_INDETERMINATE
}
STATE_UNCHECKED -> {
stateValue.value = STATE_UNCHECKED
}
STATE_CHECKED -> {
stateValue.value = STATE_CHECKED
}
}
}
// TODO process error state
addOnErrorChangedListener { checkBox, errorShown ->
}
}
}, update = { materialCheckBox ->
when (stateValue.value) {
STATE_INDETERMINATE -> {
with(materialCheckBox) {
error = "Error on CheckBox"
isErrorShown = true
errorAccessibilityLabel = "TODO"
materialCheckBox.checkedState = STATE_INDETERMINATE
}
}
else -> {
with(materialCheckBox) {
isErrorShown = false
setError("", null)
}
}
}
})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment