Last active
January 14, 2022 21:06
-
-
Save alexvanyo/332ee69d12fedabc71804aa7d22ef509 to your computer and use it in GitHub Desktop.
A Modifier to track all touch inputs on a Composable
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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