Is there a way to prevent child composables from b...
# compose
z
Is there a way to prevent child composables from being focused, through the parent?
My child composable has
Modifier.focusRequester(x)
and
requestFocus()
is called when its rendered (in a
LaunchedEffect
). As expected.. it gets the focus. Now my parent composable overlays the child composable, but the keyboard still shows up. Ideally Id like to have something akin to how I block touch events.
Copy code
private fun Modifier.disableInteractions(): Modifier {
    return pointerInput(Unit) {
        awaitPointerEventScope {
            while (true) {
                awaitPointerEvent(Initial).run {
                    changes.forEach(PointerInputChange::consume)
                }
            }
        }
    }
}
Ive tried overriding
LocalFocusManager
with a noop one, and
LocalSoftwareKeyboardController
with null; but the keyboard still shows up. I suspect Ill need to create a way to block the entire
Modifier.focusRequester(x)
part as well. Is there an easier way to go about it?
Ultimately ended up creating a
val LocalFocusEnabled: CompositionLocal<Boolean>
that I check before requesting focus. Would I have loved a better way? Yes. Does it work? Yes. If anyone knows a better approach, please enlighten me 😃
z
I think this should do it:
Copy code
Modifier.focusProperties { canFocus = false }
z
It works for the focus itself but the keyboard still shows up as a result of the disabled focus, maybe bug?
z
So you have a text field under this modifier, which doesn’t get focus, but it still shows the keyboard?
BasicTextField2 or the old one?
z
Yes, old one
z
Can you file a bug with a minimal reproducer?
If the field is showing the keyboard while not focused, that’s definitely a bug
Oh you know what it might be https://issuetracker.google.com/301477279
But still a text field bug, so please file
z
Will du tomorrow 💪🏽
gratitude thank you 1
It was a bit more complicated to repro than I thought, but here it is 😃 Apparently linked to input fields in lazy layouts, I tested
BasicTextField2
as well - but same exact behavior there too!
gratitude thank you 1
z
I suspect this has nothing to do with text but a bug in the focus system, or modifiers, so i’m not surprised
🥲 1
146 Views