Status Update
Comments
sh...@google.com <sh...@google.com> #2
I haven't tried this feature before, but it appears that you'd want to trigger it at the decor View level. We won't likely implement it beyond the ComposeView
level in the near future.
Please try that and see if it satisfies your needs.
activity.window.decorView.filterTouchesWhenObscured = true
an...@google.com <an...@google.com> #3
DecorView or the outer ComposeView is a good short term option, but doesn't provide the best user experience. On older devices, there were popular overlay apps for things like "blue-light" to make the screen easier on the eyes.
Not having finer grained control on which UI elements are sensitive would mean any taps on the screen are not processed without good explanation (scrolls, links, non sensitive content, etc...).
Many apps typically only protect UI elements that change user or device state (posting to social media, installing an app, making a purchase, etc...). Typically on the button on the screen.
Would be nice to have this improvement in Compose at a later date :)
sh...@google.com <sh...@google.com> #4
Compose doesn't have the same system of short-circuiting events as Views. However, I think you can create a modifier to mark the PointerInputChanges as consumed on Initial, then unmark it on Main, then mark it again on Final. This should disable gesture detectors in the hierarchy below the modifier. It would have to be Android-specific and we would have to access to the MotionEvent. Whether this means we expose the MotionEvent in the PointerEvent or implement this in compose:ui:ui is TBD
Description
@Composable
fun Modifier.longPressGestureFilter(
onLongPress: (PxPosition) -> Unit
): Modifier {
@Suppress("DEPRECATION")
val coroutineContext = CoroutineContextAmbient.current
val filter = remember { LongPressGestureFilter(coroutineContext) }
var coord : LayoutCoordinates? = null
filter.onLongPress = {
val coord = coord
require(coord != null && coord.isAttached)
onLongPress.invoke(it)
}
return this + PointerInputModifierImpl(filter).onPositioned {
coord = it
}
}
and run AndroidPointerInputTest.dispatchTouchEvent_pointerInputModifier_returnsTrue
this will crash because we automatically add SelectionContainer inside activity.setContent and it has longPressDragGestureFilter on it and then the test is finished and the compose hierarchy is disposed, but the coroutine is not stopped and we fire the long press with a delay for this disposed hierarchy
in my modification I added onPositioned and calling coordinates.isAttached will return false when the layout node is detached