vide
02/14/2023, 2:32 PMSlider(modifier = Modifier.focusProperties { canFocus = false }, ...)
but it doesn't seem to have any effect in some of my layouts, while it works in others. What could explain the difference and is this even the proper way to do it?
EDIT: I just realized what causes this if someone else encounters a similar problem. After dumping the focus modifier tree from the debugger I found out something is overriding the provided focusProperties, because canFocus was true in a certain parent layout. Turns out there was a parent layout element which had a disabled clickable modifier: .clickable { enabled = false }
. A relevant internal implementation detail here is that the clickable modifier also applies a focusableInNonTouchMode
modifier. More implementation details in 🧵 because this is getting quite long...internal fun Modifier.focusableInNonTouchMode(
enabled: Boolean,
interactionSource: MutableInteractionSource?
) = composed(
...
) {
val inputModeManager = LocalInputModeManager.current
Modifier
.focusProperties { canFocus = inputModeManager.inputMode != InputMode.Touch }
.focusable(enabled, interactionSource)
}
Modifier.focusable
in turn only applies a .focusTarget()
if it is enabled.focusTarget()
in turn applies a ResetFocusModifierLocals
after itself to stop the propagation of focusProperties down the node tree..focusProperties
modifier that is applied in .focusableInNonTouchMode
regardless of whether it is enabled or not leaks down the tree and overrided the focusProperties I was providing to the Slider composable.dazza5000
03/09/2023, 8:39 PMvide
03/11/2023, 4:18 PMdata class Dump(val rect: Rect, val state: FocusState, val properties: FocusProperties, val nodeItself: FocusModifier); fun traverse(node: FocusModifier): List<Any> { return listOf(Dump(node.focusRect(), node.focusState, node.focusProperties, node), node.children.map { traverse(it) }) }; traverse(focusModifier)