Skip to content

Instantly share code, notes, and snippets.

@andreymusth
Created July 19, 2021 08:42
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 andreymusth/318cc9f2e64a7ab0e303e54309b6824c to your computer and use it in GitHub Desktop.
Save andreymusth/318cc9f2e64a7ab0e303e54309b6824c to your computer and use it in GitHub Desktop.
process full
fun process(
pointerEvent: PointerInputEvent,
positionCalculator: PositionCalculator
): ProcessResult {
// Gets a new PointerInputChangeEvent with the PointerInputEvent.
val internalPointerEvent =
pointerInputChangeEventProducer.produce(pointerEvent, positionCalculator)
// Add new hit paths to the tracker due to down events.
internalPointerEvent.changes.values.forEach { pointerInputChange ->
if (pointerInputChange.changedToDownIgnoreConsumed()) {
root.hitTest(
pointerInputChange.position,
hitResult
)
if (hitResult.isNotEmpty()) {
hitPathTracker.addHitPath(pointerInputChange.id, hitResult)
hitResult.clear()
}
}
}
// Remove [PointerInputFilter]s that are no longer valid and refresh the offset information
// for those that are.
hitPathTracker.removeDetachedPointerInputFilters()
// Dispatch to PointerInputFilters
val dispatchedToSomething = hitPathTracker.dispatchChanges(internalPointerEvent)
var anyMovementConsumed = false
// Remove hit paths from the tracker due to up events, and calculate if we have consumed
// any movement
internalPointerEvent.changes.values.forEach { pointerInputChange ->
if (pointerInputChange.changedToUpIgnoreConsumed()) {
hitPathTracker.removeHitPath(pointerInputChange.id)
}
if (pointerInputChange.positionChangeConsumed()) {
anyMovementConsumed = true
}
}
return ProcessResult(dispatchedToSomething, anyMovementConsumed)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment