Skip to content

Instantly share code, notes, and snippets.

@alexvanyo
Last active January 14, 2022 21:06
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save alexvanyo/332ee69d12fedabc71804aa7d22ef509 to your computer and use it in GitHub Desktop.
Save alexvanyo/332ee69d12fedabc71804aa7d22ef509 to your computer and use it in GitHub Desktop.
A Modifier to track all touch inputs on a Composable
// Copyright 2022 Google LLC.
// SPDX-License-Identifier: Apache-2.0
/**
* A [Modifier] that tracks all input, and calls [block] every time input is received.
*/
private fun Modifier.notifyInput(block: () -> Unit): Modifier =
composed {
val currentBlock by rememberUpdatedState(block)
pointerInput(Unit) {
while (currentCoroutineContext().isActive) {
awaitPointerEventScope {
awaitPointerEvent(PointerEventPass.Initial)
currentBlock()
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment