blob: 464ae50e215b54dc8be20efabf0ba4f98dae014e [file] [log] [blame]
<html devsite="true">
<head>
<title>AwaitPointerEventScope</title>
{% setvar book_path %}/reference/kotlin/androidx/_book.yaml{% endsetvar %}
{% include "_shared/_reference-head-tags.html" %}
</head>
<body>
<div itemscope="" itemtype="http://developers.google.com/ReferenceObject">
<meta itemprop="name" content="AwaitPointerEventScope">
<meta itemprop="path" content="androidx.compose.ui.input.pointer">
<meta itemprop="property" content="awaitPointerEvent(androidx.compose.ui.input.pointer.PointerEventPass)">
<meta itemprop="property" content="withTimeout(kotlin.Long,kotlin.coroutines.SuspendFunction1)">
<meta itemprop="property" content="withTimeoutOrNull(kotlin.Long,kotlin.coroutines.SuspendFunction1)">
<meta itemprop="property" content="currentEvent()">
<meta itemprop="property" content="extendedTouchPadding()">
<meta itemprop="property" content="size()">
<meta itemprop="property" content="viewConfiguration()">
<meta itemprop="property" content="(androidx.compose.ui.input.pointer.AwaitPointerEventScope).awaitDragOrCancellation(androidx.compose.ui.input.pointer.PointerId)">
<meta itemprop="property" content="(androidx.compose.ui.input.pointer.AwaitPointerEventScope).awaitHorizontalDragOrCancellation(androidx.compose.ui.input.pointer.PointerId)">
<meta itemprop="property" content="(androidx.compose.ui.input.pointer.AwaitPointerEventScope).awaitHorizontalTouchSlopOrCancellation(androidx.compose.ui.input.pointer.PointerId,kotlin.Function2)">
<meta itemprop="property" content="(androidx.compose.ui.input.pointer.AwaitPointerEventScope).awaitLongPressOrCancellation(androidx.compose.ui.input.pointer.PointerId)">
<meta itemprop="property" content="(androidx.compose.ui.input.pointer.AwaitPointerEventScope).awaitTouchSlopOrCancellation(androidx.compose.ui.input.pointer.PointerId,kotlin.Function2)">
<meta itemprop="property" content="(androidx.compose.ui.input.pointer.AwaitPointerEventScope).awaitVerticalDragOrCancellation(androidx.compose.ui.input.pointer.PointerId)">
<meta itemprop="property" content="(androidx.compose.ui.input.pointer.AwaitPointerEventScope).awaitVerticalTouchSlopOrCancellation(androidx.compose.ui.input.pointer.PointerId,kotlin.Function2)">
<meta itemprop="property" content="(androidx.compose.ui.input.pointer.AwaitPointerEventScope).drag(androidx.compose.ui.input.pointer.PointerId,kotlin.Function1)">
<meta itemprop="property" content="(androidx.compose.ui.input.pointer.AwaitPointerEventScope).horizontalDrag(androidx.compose.ui.input.pointer.PointerId,kotlin.Function1)">
<meta itemprop="property" content="(androidx.compose.ui.input.pointer.AwaitPointerEventScope).verticalDrag(androidx.compose.ui.input.pointer.PointerId,kotlin.Function1)">
<meta itemprop="property" content="(androidx.compose.ui.input.pointer.AwaitPointerEventScope).awaitFirstDown(kotlin.Boolean,androidx.compose.ui.input.pointer.PointerEventPass)">
<meta itemprop="property" content="(androidx.compose.ui.input.pointer.AwaitPointerEventScope).waitForUpOrCancellation(androidx.compose.ui.input.pointer.PointerEventPass)">
<meta itemprop="language" content="KOTLIN">
</div>
<div id="header-block">
<div>
<h1>AwaitPointerEventScope</h1>
</div>
<div id="metadata-info-block">
<div id="source-link"><a href="https://cs.android.com/search?q=file:androidx/compose/ui/input/pointer/SuspendingPointerInputFilter.kt+class:androidx.compose.ui.input.pointer.AwaitPointerEventScope&amp;ss=androidx/platform/frameworks/support" class="external">View Source</a></div>
</div>
</div>
<div id="refdoc-switcher-placeholder"></div>
<devsite-select id="platform" label="Select a platform"><select multiple="multiple"><option selected="selected" value="platform-Common/All">Common/All</option><option selected="selected" value="platform-Android/JVM">Android/JVM</option></select></devsite-select >
<devsite-filter select-el-container-id="platform">
<div>
<ul class="list" style="list-style: none; padding-left: 0">
<li>
<div class="kotlin-platform" data-title="Common/All">Cmn</div>
<!--platform-Common/All-->
<pre>@<a href="https://kotlinlang.org/api/latest/jvm/stdlib/kotlin.coroutines/-restricts-suspension/index.html">RestrictsSuspension</a><br>interface <a href="/reference/kotlin/androidx/compose/ui/input/pointer/AwaitPointerEventScope.html">AwaitPointerEventScope</a> : <a href="/reference/kotlin/androidx/compose/ui/unit/Density.html">Density</a></pre>
</li>
</ul>
</div>
</devsite-filter >
<hr>
<p>Receiver scope for awaiting pointer events in a call to <code><a href="/reference/kotlin/androidx/compose/ui/input/pointer/PointerInputScope.html#awaitPointerEventScope(kotlin.coroutines.SuspendFunction1)">PointerInputScope.awaitPointerEventScope</a></code>.</p>
<p>This is a restricted suspension scope. Code in this scope is always called un-dispatched and may only suspend for calls to <code><a href="/reference/kotlin/androidx/compose/ui/input/pointer/AwaitPointerEventScope.html#awaitPointerEvent(androidx.compose.ui.input.pointer.PointerEventPass)">awaitPointerEvent</a></code>. These functions resume synchronously and the caller may mutate the result <b>before</b> the next await call to affect the next stage of the input processing pipeline.</p>
<h2>Summary</h2>
<div class="devsite-table-wrapper">
<devsite-filter select-el-container-id="platform">
<table class="fixed">
<colgroup>
<col width="35%">
<col width="58%">
<col>
</colgroup>
<thead>
<tr>
<th colspan="100%"><h3>Public functions</h3></th>
</tr>
</thead>
<tbody class="list">
<tr>
<td><code>suspend <a href="/reference/kotlin/androidx/compose/ui/input/pointer/PointerEvent.html">PointerEvent</a></code></td>
<td>
<div><code><a href="/reference/kotlin/androidx/compose/ui/input/pointer/AwaitPointerEventScope.html#awaitPointerEvent(androidx.compose.ui.input.pointer.PointerEventPass)">awaitPointerEvent</a>(pass:&nbsp;<a href="/reference/kotlin/androidx/compose/ui/input/pointer/PointerEventPass.html">PointerEventPass</a>)</code></div>
<p>Suspend until a <code><a href="/reference/kotlin/androidx/compose/ui/input/pointer/PointerEvent.html">PointerEvent</a></code> is reported to the specified input <code><a href="/reference/kotlin/androidx/compose/ui/input/pointer/AwaitPointerEventScope.html#awaitPointerEvent(androidx.compose.ui.input.pointer.PointerEventPass)">pass</a></code>.</p>
</td>
<td>
<div class="kotlin-platform" data-title="Common/All">Cmn</div>
<!--platform-Common/All--></td>
</tr>
<tr>
<td><code>open&nbsp;suspend T</code></td>
<td>
<div><code>&lt;T&nbsp;:&nbsp;<a href="https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-any/index.html">Any</a>?&gt; <a href="/reference/kotlin/androidx/compose/ui/input/pointer/AwaitPointerEventScope.html#withTimeout(kotlin.Long,kotlin.coroutines.SuspendFunction1)">withTimeout</a>(timeMillis:&nbsp;<a href="https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-long/index.html">Long</a>,&nbsp;block:&nbsp;suspend&nbsp;<a href="/reference/kotlin/androidx/compose/ui/input/pointer/AwaitPointerEventScope.html">AwaitPointerEventScope</a>.() <span style="white-space: nowrap;">-&gt;</span> T)</code></div>
<p>Runs <code><a href="/reference/kotlin/androidx/compose/ui/input/pointer/AwaitPointerEventScope.html#withTimeout(kotlin.Long,kotlin.coroutines.SuspendFunction1)">block</a></code> and returns its results.</p>
</td>
<td>
<div class="kotlin-platform" data-title="Common/All">Cmn</div>
<!--platform-Common/All--></td>
</tr>
<tr>
<td><code>open&nbsp;suspend T?</code></td>
<td>
<div><code>&lt;T&nbsp;:&nbsp;<a href="https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-any/index.html">Any</a>?&gt; <a href="/reference/kotlin/androidx/compose/ui/input/pointer/AwaitPointerEventScope.html#withTimeoutOrNull(kotlin.Long,kotlin.coroutines.SuspendFunction1)">withTimeoutOrNull</a>(timeMillis:&nbsp;<a href="https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-long/index.html">Long</a>,&nbsp;block:&nbsp;suspend&nbsp;<a href="/reference/kotlin/androidx/compose/ui/input/pointer/AwaitPointerEventScope.html">AwaitPointerEventScope</a>.() <span style="white-space: nowrap;">-&gt;</span> T)</code></div>
<p>Runs <code><a href="/reference/kotlin/androidx/compose/ui/input/pointer/AwaitPointerEventScope.html#withTimeoutOrNull(kotlin.Long,kotlin.coroutines.SuspendFunction1)">block</a></code> and returns the result of <code><a href="/reference/kotlin/androidx/compose/ui/input/pointer/AwaitPointerEventScope.html#withTimeoutOrNull(kotlin.Long,kotlin.coroutines.SuspendFunction1)">block</a></code> or <code>null</code> if <code><a href="/reference/kotlin/androidx/compose/ui/input/pointer/AwaitPointerEventScope.html#withTimeoutOrNull(kotlin.Long,kotlin.coroutines.SuspendFunction1)">timeMillis</a></code> has passed before <code><a href="/reference/kotlin/androidx/compose/ui/input/pointer/AwaitPointerEventScope.html#withTimeoutOrNull(kotlin.Long,kotlin.coroutines.SuspendFunction1)">timeMillis</a></code>.</p>
</td>
<td>
<div class="kotlin-platform" data-title="Common/All">Cmn</div>
<!--platform-Common/All--></td>
</tr>
</tbody>
</table>
</devsite-filter >
</div>
<div class="devsite-table-wrapper">
<devsite-filter select-el-container-id="platform">
<table class="fixed">
<colgroup>
<col width="35%">
<col width="58%">
<col>
</colgroup>
<thead>
<tr>
<th colspan="100%"><h3>Public properties</h3></th>
</tr>
</thead>
<tbody class="list">
<tr>
<td><code><a href="/reference/kotlin/androidx/compose/ui/input/pointer/PointerEvent.html">PointerEvent</a></code></td>
<td>
<div><code><a href="/reference/kotlin/androidx/compose/ui/input/pointer/AwaitPointerEventScope.html#currentEvent()">currentEvent</a></code></div>
<p>The <code><a href="/reference/kotlin/androidx/compose/ui/input/pointer/PointerEvent.html">PointerEvent</a></code> from the most recent touch event.</p>
</td>
<td>
<div class="kotlin-platform" data-title="Common/All">Cmn</div>
<!--platform-Common/All--></td>
</tr>
<tr>
<td><code>open <a href="/reference/kotlin/androidx/compose/ui/geometry/Size.html">Size</a></code></td>
<td>
<div><code><a href="/reference/kotlin/androidx/compose/ui/input/pointer/AwaitPointerEventScope.html#extendedTouchPadding()">extendedTouchPadding</a></code></div>
</td>
<td>
<div class="kotlin-platform" data-title="Common/All">Cmn</div>
<!--platform-Common/All--></td>
</tr>
<tr>
<td><code><a href="/reference/kotlin/androidx/compose/ui/unit/IntSize.html">IntSize</a></code></td>
<td>
<div><code><a href="/reference/kotlin/androidx/compose/ui/input/pointer/AwaitPointerEventScope.html#size()">size</a></code></div>
<p>The measured size of the pointer input region.</p>
</td>
<td>
<div class="kotlin-platform" data-title="Common/All">Cmn</div>
<!--platform-Common/All--></td>
</tr>
<tr>
<td><code><a href="/reference/kotlin/androidx/compose/ui/platform/ViewConfiguration.html">ViewConfiguration</a></code></td>
<td>
<div><code><a href="/reference/kotlin/androidx/compose/ui/input/pointer/AwaitPointerEventScope.html#viewConfiguration()">viewConfiguration</a></code></div>
<p>The <code><a href="/reference/kotlin/androidx/compose/ui/platform/ViewConfiguration.html">ViewConfiguration</a></code> used to tune gesture detectors.</p>
</td>
<td>
<div class="kotlin-platform" data-title="Common/All">Cmn</div>
<!--platform-Common/All--></td>
</tr>
</tbody>
</table>
</devsite-filter >
</div>
<div class="devsite-table-wrapper">
<devsite-filter select-el-container-id="platform">
<table class="fixed">
<colgroup>
<col width="35%">
<col width="58%">
<col>
</colgroup>
<thead>
<tr>
<th colspan="100%"><h3>Extension functions</h3></th>
</tr>
</thead>
<tbody class="list">
<tr>
<td><code>suspend <a href="/reference/kotlin/androidx/compose/ui/input/pointer/PointerInputChange.html">PointerInputChange</a>?</code></td>
<td>
<div><code><a href="/reference/kotlin/androidx/compose/ui/input/pointer/AwaitPointerEventScope.html">AwaitPointerEventScope</a>.<a href="/reference/kotlin/androidx/compose/ui/input/pointer/AwaitPointerEventScope.html#(androidx.compose.ui.input.pointer.AwaitPointerEventScope).awaitDragOrCancellation(androidx.compose.ui.input.pointer.PointerId)">awaitDragOrCancellation</a>(pointerId:&nbsp;<a href="/reference/kotlin/androidx/compose/ui/input/pointer/PointerId.html">PointerId</a>)</code></div>
<p>Reads pointer input events until a drag is detected or all pointers are up.</p>
</td>
<td>
<div class="kotlin-platform" data-title="Common/All">Cmn</div>
<!--platform-Common/All--></td>
</tr>
<tr>
<td><code>suspend <a href="/reference/kotlin/androidx/compose/ui/input/pointer/PointerInputChange.html">PointerInputChange</a>?</code></td>
<td>
<div><code><a href="/reference/kotlin/androidx/compose/ui/input/pointer/AwaitPointerEventScope.html">AwaitPointerEventScope</a>.<a href="/reference/kotlin/androidx/compose/ui/input/pointer/AwaitPointerEventScope.html#(androidx.compose.ui.input.pointer.AwaitPointerEventScope).awaitHorizontalDragOrCancellation(androidx.compose.ui.input.pointer.PointerId)">awaitHorizontalDragOrCancellation</a>(<br>&nbsp;&nbsp;&nbsp;&nbsp;pointerId:&nbsp;<a href="/reference/kotlin/androidx/compose/ui/input/pointer/PointerId.html">PointerId</a><br>)</code></div>
<p>Reads pointer input events until a horizontal drag is detected or all pointers are up.</p>
</td>
<td>
<div class="kotlin-platform" data-title="Common/All">Cmn</div>
<!--platform-Common/All--></td>
</tr>
<tr>
<td><code>suspend <a href="/reference/kotlin/androidx/compose/ui/input/pointer/PointerInputChange.html">PointerInputChange</a>?</code></td>
<td>
<div><code><a href="/reference/kotlin/androidx/compose/ui/input/pointer/AwaitPointerEventScope.html">AwaitPointerEventScope</a>.<a href="/reference/kotlin/androidx/compose/ui/input/pointer/AwaitPointerEventScope.html#(androidx.compose.ui.input.pointer.AwaitPointerEventScope).awaitHorizontalTouchSlopOrCancellation(androidx.compose.ui.input.pointer.PointerId,kotlin.Function2)">awaitHorizontalTouchSlopOrCancellation</a>(<br>&nbsp;&nbsp;&nbsp;&nbsp;pointerId:&nbsp;<a href="/reference/kotlin/androidx/compose/ui/input/pointer/PointerId.html">PointerId</a>,<br>&nbsp;&nbsp;&nbsp;&nbsp;onTouchSlopReached:&nbsp;(change:&nbsp;<a href="/reference/kotlin/androidx/compose/ui/input/pointer/PointerInputChange.html">PointerInputChange</a>, overSlop:&nbsp;<a href="https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-float/index.html">Float</a>) <span style="white-space: nowrap;">-&gt;</span> <a href="https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-unit/index.html">Unit</a><br>)</code></div>
<p>Waits for horizontal drag motion to pass <code><a href="/reference/kotlin/androidx/compose/ui/platform/ViewConfiguration.html#touchSlop()">touch slop</a></code>, using <code><a href="/reference/kotlin/androidx/compose/foundation/gestures/package-summary.html#(androidx.compose.ui.input.pointer.AwaitPointerEventScope).awaitHorizontalTouchSlopOrCancellation(androidx.compose.ui.input.pointer.PointerId,kotlin.Function2)">pointerId</a></code> as the pointer to examine.</p>
</td>
<td>
<div class="kotlin-platform" data-title="Common/All">Cmn</div>
<!--platform-Common/All--></td>
</tr>
<tr>
<td><code>suspend <a href="/reference/kotlin/androidx/compose/ui/input/pointer/PointerInputChange.html">PointerInputChange</a>?</code></td>
<td>
<div><code><a href="/reference/kotlin/androidx/compose/ui/input/pointer/AwaitPointerEventScope.html">AwaitPointerEventScope</a>.<a href="/reference/kotlin/androidx/compose/ui/input/pointer/AwaitPointerEventScope.html#(androidx.compose.ui.input.pointer.AwaitPointerEventScope).awaitLongPressOrCancellation(androidx.compose.ui.input.pointer.PointerId)">awaitLongPressOrCancellation</a>(<br>&nbsp;&nbsp;&nbsp;&nbsp;pointerId:&nbsp;<a href="/reference/kotlin/androidx/compose/ui/input/pointer/PointerId.html">PointerId</a><br>)</code></div>
<p>Waits for a long press by examining <code><a href="/reference/kotlin/androidx/compose/foundation/gestures/package-summary.html#(androidx.compose.ui.input.pointer.AwaitPointerEventScope).awaitLongPressOrCancellation(androidx.compose.ui.input.pointer.PointerId)">pointerId</a></code>.</p>
</td>
<td>
<div class="kotlin-platform" data-title="Common/All">Cmn</div>
<!--platform-Common/All--></td>
</tr>
<tr>
<td><code>suspend <a href="/reference/kotlin/androidx/compose/ui/input/pointer/PointerInputChange.html">PointerInputChange</a>?</code></td>
<td>
<div><code><a href="/reference/kotlin/androidx/compose/ui/input/pointer/AwaitPointerEventScope.html">AwaitPointerEventScope</a>.<a href="/reference/kotlin/androidx/compose/ui/input/pointer/AwaitPointerEventScope.html#(androidx.compose.ui.input.pointer.AwaitPointerEventScope).awaitTouchSlopOrCancellation(androidx.compose.ui.input.pointer.PointerId,kotlin.Function2)">awaitTouchSlopOrCancellation</a>(<br>&nbsp;&nbsp;&nbsp;&nbsp;pointerId:&nbsp;<a href="/reference/kotlin/androidx/compose/ui/input/pointer/PointerId.html">PointerId</a>,<br>&nbsp;&nbsp;&nbsp;&nbsp;onTouchSlopReached:&nbsp;(change:&nbsp;<a href="/reference/kotlin/androidx/compose/ui/input/pointer/PointerInputChange.html">PointerInputChange</a>, overSlop:&nbsp;<a href="/reference/kotlin/androidx/compose/ui/geometry/Offset.html">Offset</a>) <span style="white-space: nowrap;">-&gt;</span> <a href="https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-unit/index.html">Unit</a><br>)</code></div>
<p>Waits for drag motion to pass <code><a href="/reference/kotlin/androidx/compose/ui/platform/ViewConfiguration.html#touchSlop()">touch slop</a></code>, using <code><a href="/reference/kotlin/androidx/compose/foundation/gestures/package-summary.html#(androidx.compose.ui.input.pointer.AwaitPointerEventScope).awaitTouchSlopOrCancellation(androidx.compose.ui.input.pointer.PointerId,kotlin.Function2)">pointerId</a></code> as the pointer to examine.</p>
</td>
<td>
<div class="kotlin-platform" data-title="Common/All">Cmn</div>
<!--platform-Common/All--></td>
</tr>
<tr>
<td><code>suspend <a href="/reference/kotlin/androidx/compose/ui/input/pointer/PointerInputChange.html">PointerInputChange</a>?</code></td>
<td>
<div><code><a href="/reference/kotlin/androidx/compose/ui/input/pointer/AwaitPointerEventScope.html">AwaitPointerEventScope</a>.<a href="/reference/kotlin/androidx/compose/ui/input/pointer/AwaitPointerEventScope.html#(androidx.compose.ui.input.pointer.AwaitPointerEventScope).awaitVerticalDragOrCancellation(androidx.compose.ui.input.pointer.PointerId)">awaitVerticalDragOrCancellation</a>(<br>&nbsp;&nbsp;&nbsp;&nbsp;pointerId:&nbsp;<a href="/reference/kotlin/androidx/compose/ui/input/pointer/PointerId.html">PointerId</a><br>)</code></div>
<p>Reads pointer input events until a vertical drag is detected or all pointers are up.</p>
</td>
<td>
<div class="kotlin-platform" data-title="Common/All">Cmn</div>
<!--platform-Common/All--></td>
</tr>
<tr>
<td><code>suspend <a href="/reference/kotlin/androidx/compose/ui/input/pointer/PointerInputChange.html">PointerInputChange</a>?</code></td>
<td>
<div><code><a href="/reference/kotlin/androidx/compose/ui/input/pointer/AwaitPointerEventScope.html">AwaitPointerEventScope</a>.<a href="/reference/kotlin/androidx/compose/ui/input/pointer/AwaitPointerEventScope.html#(androidx.compose.ui.input.pointer.AwaitPointerEventScope).awaitVerticalTouchSlopOrCancellation(androidx.compose.ui.input.pointer.PointerId,kotlin.Function2)">awaitVerticalTouchSlopOrCancellation</a>(<br>&nbsp;&nbsp;&nbsp;&nbsp;pointerId:&nbsp;<a href="/reference/kotlin/androidx/compose/ui/input/pointer/PointerId.html">PointerId</a>,<br>&nbsp;&nbsp;&nbsp;&nbsp;onTouchSlopReached:&nbsp;(change:&nbsp;<a href="/reference/kotlin/androidx/compose/ui/input/pointer/PointerInputChange.html">PointerInputChange</a>, overSlop:&nbsp;<a href="https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-float/index.html">Float</a>) <span style="white-space: nowrap;">-&gt;</span> <a href="https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-unit/index.html">Unit</a><br>)</code></div>
<p>Waits for vertical drag motion to pass <code><a href="/reference/kotlin/androidx/compose/ui/platform/ViewConfiguration.html#touchSlop()">touch slop</a></code>, using <code><a href="/reference/kotlin/androidx/compose/foundation/gestures/package-summary.html#(androidx.compose.ui.input.pointer.AwaitPointerEventScope).awaitVerticalTouchSlopOrCancellation(androidx.compose.ui.input.pointer.PointerId,kotlin.Function2)">pointerId</a></code> as the pointer to examine.</p>
</td>
<td>
<div class="kotlin-platform" data-title="Common/All">Cmn</div>
<!--platform-Common/All--></td>
</tr>
<tr>
<td><code>suspend <a href="https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-boolean/index.html">Boolean</a></code></td>
<td>
<div><code><a href="/reference/kotlin/androidx/compose/ui/input/pointer/AwaitPointerEventScope.html">AwaitPointerEventScope</a>.<a href="/reference/kotlin/androidx/compose/ui/input/pointer/AwaitPointerEventScope.html#(androidx.compose.ui.input.pointer.AwaitPointerEventScope).drag(androidx.compose.ui.input.pointer.PointerId,kotlin.Function1)">drag</a>(<br>&nbsp;&nbsp;&nbsp;&nbsp;pointerId:&nbsp;<a href="/reference/kotlin/androidx/compose/ui/input/pointer/PointerId.html">PointerId</a>,<br>&nbsp;&nbsp;&nbsp;&nbsp;onDrag:&nbsp;(<a href="/reference/kotlin/androidx/compose/ui/input/pointer/PointerInputChange.html">PointerInputChange</a>) <span style="white-space: nowrap;">-&gt;</span> <a href="https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-unit/index.html">Unit</a><br>)</code></div>
<p>Reads position change events for <code><a href="/reference/kotlin/androidx/compose/foundation/gestures/package-summary.html#(androidx.compose.ui.input.pointer.AwaitPointerEventScope).drag(androidx.compose.ui.input.pointer.PointerId,kotlin.Function1)">pointerId</a></code> and calls <code><a href="/reference/kotlin/androidx/compose/foundation/gestures/package-summary.html#(androidx.compose.ui.input.pointer.AwaitPointerEventScope).drag(androidx.compose.ui.input.pointer.PointerId,kotlin.Function1)">onDrag</a></code> for every change in position.</p>
</td>
<td>
<div class="kotlin-platform" data-title="Common/All">Cmn</div>
<!--platform-Common/All--></td>
</tr>
<tr>
<td><code>suspend <a href="https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-boolean/index.html">Boolean</a></code></td>
<td>
<div><code><a href="/reference/kotlin/androidx/compose/ui/input/pointer/AwaitPointerEventScope.html">AwaitPointerEventScope</a>.<a href="/reference/kotlin/androidx/compose/ui/input/pointer/AwaitPointerEventScope.html#(androidx.compose.ui.input.pointer.AwaitPointerEventScope).horizontalDrag(androidx.compose.ui.input.pointer.PointerId,kotlin.Function1)">horizontalDrag</a>(<br>&nbsp;&nbsp;&nbsp;&nbsp;pointerId:&nbsp;<a href="/reference/kotlin/androidx/compose/ui/input/pointer/PointerId.html">PointerId</a>,<br>&nbsp;&nbsp;&nbsp;&nbsp;onDrag:&nbsp;(<a href="/reference/kotlin/androidx/compose/ui/input/pointer/PointerInputChange.html">PointerInputChange</a>) <span style="white-space: nowrap;">-&gt;</span> <a href="https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-unit/index.html">Unit</a><br>)</code></div>
<p>Reads horizontal position change events for <code><a href="/reference/kotlin/androidx/compose/foundation/gestures/package-summary.html#(androidx.compose.ui.input.pointer.AwaitPointerEventScope).horizontalDrag(androidx.compose.ui.input.pointer.PointerId,kotlin.Function1)">pointerId</a></code> and calls <code><a href="/reference/kotlin/androidx/compose/foundation/gestures/package-summary.html#(androidx.compose.ui.input.pointer.AwaitPointerEventScope).horizontalDrag(androidx.compose.ui.input.pointer.PointerId,kotlin.Function1)">onDrag</a></code> for every change in position.</p>
</td>
<td>
<div class="kotlin-platform" data-title="Common/All">Cmn</div>
<!--platform-Common/All--></td>
</tr>
<tr>
<td><code>suspend <a href="https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-boolean/index.html">Boolean</a></code></td>
<td>
<div><code><a href="/reference/kotlin/androidx/compose/ui/input/pointer/AwaitPointerEventScope.html">AwaitPointerEventScope</a>.<a href="/reference/kotlin/androidx/compose/ui/input/pointer/AwaitPointerEventScope.html#(androidx.compose.ui.input.pointer.AwaitPointerEventScope).verticalDrag(androidx.compose.ui.input.pointer.PointerId,kotlin.Function1)">verticalDrag</a>(<br>&nbsp;&nbsp;&nbsp;&nbsp;pointerId:&nbsp;<a href="/reference/kotlin/androidx/compose/ui/input/pointer/PointerId.html">PointerId</a>,<br>&nbsp;&nbsp;&nbsp;&nbsp;onDrag:&nbsp;(<a href="/reference/kotlin/androidx/compose/ui/input/pointer/PointerInputChange.html">PointerInputChange</a>) <span style="white-space: nowrap;">-&gt;</span> <a href="https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-unit/index.html">Unit</a><br>)</code></div>
<p>Reads vertical position change events for <code><a href="/reference/kotlin/androidx/compose/foundation/gestures/package-summary.html#(androidx.compose.ui.input.pointer.AwaitPointerEventScope).verticalDrag(androidx.compose.ui.input.pointer.PointerId,kotlin.Function1)">pointerId</a></code> and calls <code><a href="/reference/kotlin/androidx/compose/foundation/gestures/package-summary.html#(androidx.compose.ui.input.pointer.AwaitPointerEventScope).verticalDrag(androidx.compose.ui.input.pointer.PointerId,kotlin.Function1)">onDrag</a></code> for every change in position.</p>
</td>
<td>
<div class="kotlin-platform" data-title="Common/All">Cmn</div>
<!--platform-Common/All--></td>
</tr>
<tr>
<td><code>suspend <a href="/reference/kotlin/androidx/compose/ui/input/pointer/PointerInputChange.html">PointerInputChange</a></code></td>
<td>
<div><code><a href="/reference/kotlin/androidx/compose/ui/input/pointer/AwaitPointerEventScope.html">AwaitPointerEventScope</a>.<a href="/reference/kotlin/androidx/compose/ui/input/pointer/AwaitPointerEventScope.html#(androidx.compose.ui.input.pointer.AwaitPointerEventScope).awaitFirstDown(kotlin.Boolean,androidx.compose.ui.input.pointer.PointerEventPass)">awaitFirstDown</a>(<br>&nbsp;&nbsp;&nbsp;&nbsp;requireUnconsumed:&nbsp;<a href="https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-boolean/index.html">Boolean</a>,<br>&nbsp;&nbsp;&nbsp;&nbsp;pass:&nbsp;<a href="/reference/kotlin/androidx/compose/ui/input/pointer/PointerEventPass.html">PointerEventPass</a><br>)</code></div>
<p>Reads events until the first down is received in the given <code><a href="/reference/kotlin/androidx/compose/foundation/gestures/package-summary.html#(androidx.compose.ui.input.pointer.AwaitPointerEventScope).awaitFirstDown(kotlin.Boolean,androidx.compose.ui.input.pointer.PointerEventPass)">pass</a></code>.</p>
</td>
<td>
<div class="kotlin-platform" data-title="Common/All">Cmn</div>
<!--platform-Common/All--></td>
</tr>
<tr>
<td><code>suspend <a href="/reference/kotlin/androidx/compose/ui/input/pointer/PointerInputChange.html">PointerInputChange</a>?</code></td>
<td>
<div><code><a href="/reference/kotlin/androidx/compose/ui/input/pointer/AwaitPointerEventScope.html">AwaitPointerEventScope</a>.<a href="/reference/kotlin/androidx/compose/ui/input/pointer/AwaitPointerEventScope.html#(androidx.compose.ui.input.pointer.AwaitPointerEventScope).waitForUpOrCancellation(androidx.compose.ui.input.pointer.PointerEventPass)">waitForUpOrCancellation</a>(pass:&nbsp;<a href="/reference/kotlin/androidx/compose/ui/input/pointer/PointerEventPass.html">PointerEventPass</a>)</code></div>
<p>Reads events in the given <code><a href="/reference/kotlin/androidx/compose/foundation/gestures/package-summary.html#(androidx.compose.ui.input.pointer.AwaitPointerEventScope).waitForUpOrCancellation(androidx.compose.ui.input.pointer.PointerEventPass)">pass</a></code> until all pointers are up or the gesture was canceled.</p>
</td>
<td>
<div class="kotlin-platform" data-title="Common/All">Cmn</div>
<!--platform-Common/All--></td>
</tr>
</tbody>
</table>
</devsite-filter >
</div>
<div class="devsite-table-wrapper">
<table class="responsive" id="inhmethods">
<thead>
<tr>
<th colspan="100%"><h3>Inherited functions</h3></th>
</tr>
</thead>
<tbody class="list">
<tr>
<td><devsite-expandable><span class="expand-control">From <a href="/reference/kotlin/androidx/compose/ui/unit/Density.html">androidx.compose.ui.unit.Density</a></span>
<div class="devsite-table-wrapper">
<devsite-filter select-el-container-id="platform">
<table class="fixed">
<colgroup>
<col width="35%">
<col width="58%">
<col>
</colgroup>
<tbody class="list">
<tr>
<td><code>open <a href="https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-int/index.html">Int</a></code></td>
<td>
<div><code><a href="/reference/kotlin/androidx/compose/ui/unit/Dp.html">Dp</a>.<a href="/reference/kotlin/androidx/compose/ui/unit/Density.html#(androidx.compose.ui.unit.Dp).roundToPx()">roundToPx</a>()</code></div>
<p>Convert <code><a href="/reference/kotlin/androidx/compose/ui/unit/Dp.html">Dp</a></code> to <code><a href="https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-int/index.html">Int</a></code> by rounding</p>
</td>
<td>
<div class="kotlin-platform" data-title="Common/All">Cmn</div>
<!--platform-Common/All--></td>
</tr>
<tr>
<td><code>open <a href="https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-int/index.html">Int</a></code></td>
<td>
<div><code><a href="/reference/kotlin/androidx/compose/ui/unit/TextUnit.html">TextUnit</a>.<a href="/reference/kotlin/androidx/compose/ui/unit/Density.html#(androidx.compose.ui.unit.TextUnit).roundToPx()">roundToPx</a>()</code></div>
<p>Convert Sp to <code><a href="https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-int/index.html">Int</a></code> by rounding</p>
</td>
<td>
<div class="kotlin-platform" data-title="Common/All">Cmn</div>
<!--platform-Common/All--></td>
</tr>
<tr>
<td><code>open <a href="/reference/kotlin/androidx/compose/ui/unit/Dp.html">Dp</a></code></td>
<td>
<div><code><a href="/reference/kotlin/androidx/compose/ui/unit/TextUnit.html">TextUnit</a>.<a href="/reference/kotlin/androidx/compose/ui/unit/Density.html#(androidx.compose.ui.unit.TextUnit).toDp()">toDp</a>()</code></div>
<p>Convert Sp to <code><a href="/reference/kotlin/androidx/compose/ui/unit/Dp.html">Dp</a></code>.</p>
</td>
<td>
<div class="kotlin-platform" data-title="Common/All">Cmn</div>
<!--platform-Common/All--></td>
</tr>
<tr>
<td><code>open <a href="/reference/kotlin/androidx/compose/ui/unit/Dp.html">Dp</a></code></td>
<td>
<div><code><a href="https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-int/index.html">Int</a>.<a href="/reference/kotlin/androidx/compose/ui/unit/Density.html#(kotlin.Int).toDp()">toDp</a>()</code></div>
<p>Convert an <code><a href="https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-int/index.html">Int</a></code> pixel value to <code><a href="/reference/kotlin/androidx/compose/ui/unit/Dp.html">Dp</a></code>.</p>
</td>
<td>
<div class="kotlin-platform" data-title="Common/All">Cmn</div>
<!--platform-Common/All--></td>
</tr>
<tr>
<td><code>open <a href="/reference/kotlin/androidx/compose/ui/unit/Dp.html">Dp</a></code></td>
<td>
<div><code><a href="https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-float/index.html">Float</a>.<a href="/reference/kotlin/androidx/compose/ui/unit/Density.html#(kotlin.Float).toDp()">toDp</a>()</code></div>
<p>Convert a <code><a href="https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-float/index.html">Float</a></code> pixel value to a Dp</p>
</td>
<td>
<div class="kotlin-platform" data-title="Common/All">Cmn</div>
<!--platform-Common/All--></td>
</tr>
<tr>
<td><code>open <a href="/reference/kotlin/androidx/compose/ui/unit/DpSize.html">DpSize</a></code></td>
<td>
<div><code><a href="/reference/kotlin/androidx/compose/ui/geometry/Size.html">Size</a>.<a href="/reference/kotlin/androidx/compose/ui/unit/Density.html#(androidx.compose.ui.geometry.Size).toDpSize()">toDpSize</a>()</code></div>
<p>Convert a <code><a href="/reference/kotlin/androidx/compose/ui/geometry/Size.html">Size</a></code> to a <code><a href="/reference/kotlin/androidx/compose/ui/unit/DpSize.html">DpSize</a></code>.</p>
</td>
<td>
<div class="kotlin-platform" data-title="Common/All">Cmn</div>
<!--platform-Common/All--></td>
</tr>
<tr>
<td><code>open <a href="https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-float/index.html">Float</a></code></td>
<td>
<div><code><a href="/reference/kotlin/androidx/compose/ui/unit/Dp.html">Dp</a>.<a href="/reference/kotlin/androidx/compose/ui/unit/Density.html#(androidx.compose.ui.unit.Dp).toPx()">toPx</a>()</code></div>
<p>Convert <code><a href="/reference/kotlin/androidx/compose/ui/unit/Dp.html">Dp</a></code> to pixels.</p>
</td>
<td>
<div class="kotlin-platform" data-title="Common/All">Cmn</div>
<!--platform-Common/All--></td>
</tr>
<tr>
<td><code>open <a href="https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-float/index.html">Float</a></code></td>
<td>
<div><code><a href="/reference/kotlin/androidx/compose/ui/unit/TextUnit.html">TextUnit</a>.<a href="/reference/kotlin/androidx/compose/ui/unit/Density.html#(androidx.compose.ui.unit.TextUnit).toPx()">toPx</a>()</code></div>
<p>Convert Sp to pixels.</p>
</td>
<td>
<div class="kotlin-platform" data-title="Common/All">Cmn</div>
<!--platform-Common/All--></td>
</tr>
<tr>
<td><code>open <a href="/reference/kotlin/androidx/compose/ui/geometry/Rect.html">Rect</a></code></td>
<td>
<div><code><a href="/reference/kotlin/androidx/compose/ui/unit/DpRect.html">DpRect</a>.<a href="/reference/kotlin/androidx/compose/ui/unit/Density.html#(androidx.compose.ui.unit.DpRect).toRect()">toRect</a>()</code></div>
<p>Convert a <code><a href="/reference/kotlin/androidx/compose/ui/unit/DpRect.html">DpRect</a></code> to a <code><a href="/reference/kotlin/androidx/compose/ui/geometry/Rect.html">Rect</a></code>.</p>
</td>
<td>
<div class="kotlin-platform" data-title="Common/All">Cmn</div>
<!--platform-Common/All--></td>
</tr>
<tr>
<td><code>open <a href="/reference/kotlin/androidx/compose/ui/geometry/Size.html">Size</a></code></td>
<td>
<div><code><a href="/reference/kotlin/androidx/compose/ui/unit/DpSize.html">DpSize</a>.<a href="/reference/kotlin/androidx/compose/ui/unit/Density.html#(androidx.compose.ui.unit.DpSize).toSize()">toSize</a>()</code></div>
<p>Convert a <code><a href="/reference/kotlin/androidx/compose/ui/unit/DpSize.html">DpSize</a></code> to a <code><a href="/reference/kotlin/androidx/compose/ui/geometry/Size.html">Size</a></code>.</p>
</td>
<td>
<div class="kotlin-platform" data-title="Common/All">Cmn</div>
<!--platform-Common/All--></td>
</tr>
<tr>
<td><code>open <a href="/reference/kotlin/androidx/compose/ui/unit/TextUnit.html">TextUnit</a></code></td>
<td>
<div><code><a href="/reference/kotlin/androidx/compose/ui/unit/Dp.html">Dp</a>.<a href="/reference/kotlin/androidx/compose/ui/unit/Density.html#(androidx.compose.ui.unit.Dp).toSp()">toSp</a>()</code></div>
<p>Convert <code><a href="/reference/kotlin/androidx/compose/ui/unit/Dp.html">Dp</a></code> to Sp.</p>
</td>
<td>
<div class="kotlin-platform" data-title="Common/All">Cmn</div>
<!--platform-Common/All--></td>
</tr>
<tr>
<td><code>open <a href="/reference/kotlin/androidx/compose/ui/unit/TextUnit.html">TextUnit</a></code></td>
<td>
<div><code><a href="https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-int/index.html">Int</a>.<a href="/reference/kotlin/androidx/compose/ui/unit/Density.html#(kotlin.Int).toSp()">toSp</a>()</code></div>
<p>Convert an <code><a href="https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-int/index.html">Int</a></code> pixel value to Sp.</p>
</td>
<td>
<div class="kotlin-platform" data-title="Common/All">Cmn</div>
<!--platform-Common/All--></td>
</tr>
<tr>
<td><code>open <a href="/reference/kotlin/androidx/compose/ui/unit/TextUnit.html">TextUnit</a></code></td>
<td>
<div><code><a href="https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-float/index.html">Float</a>.<a href="/reference/kotlin/androidx/compose/ui/unit/Density.html#(kotlin.Float).toSp()">toSp</a>()</code></div>
<p>Convert a <code><a href="https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-float/index.html">Float</a></code> pixel value to a Sp</p>
</td>
<td>
<div class="kotlin-platform" data-title="Common/All">Cmn</div>
<!--platform-Common/All--></td>
</tr>
</tbody>
</table>
</devsite-filter >
</div>
</devsite-expandable> </td>
</tr>
</tbody>
</table>
</div>
<div class="devsite-table-wrapper">
<table class="responsive" id="inhmethods">
<thead>
<tr>
<th colspan="100%"><h3>Inherited properties</h3></th>
</tr>
</thead>
<tbody class="list">
<tr>
<td><devsite-expandable><span class="expand-control">From <a href="/reference/kotlin/androidx/compose/ui/unit/Density.html">androidx.compose.ui.unit.Density</a></span>
<div class="devsite-table-wrapper">
<devsite-filter select-el-container-id="platform">
<table class="fixed">
<colgroup>
<col width="35%">
<col width="58%">
<col>
</colgroup>
<tbody class="list">
<tr>
<td><code><a href="https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-float/index.html">Float</a></code></td>
<td>
<div><code><a href="/reference/kotlin/androidx/compose/ui/unit/Density.html#density()">density</a></code></div>
<p>The logical density of the display.</p>
</td>
<td>
<div class="kotlin-platform" data-title="Common/All">Cmn</div>
<!--platform-Common/All--></td>
</tr>
<tr>
<td><code><a href="https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-float/index.html">Float</a></code></td>
<td>
<div><code><a href="/reference/kotlin/androidx/compose/ui/unit/Density.html#fontScale()">fontScale</a></code></div>
<p>Current user preference for the scaling factor for fonts.</p>
</td>
<td>
<div class="kotlin-platform" data-title="Common/All">Cmn</div>
<!--platform-Common/All--></td>
</tr>
</tbody>
</table>
</devsite-filter >
</div>
</devsite-expandable> </td>
</tr>
</tbody>
</table>
</div>
<devsite-filter select-el-container-id="platform">
<div class="list">
<h2 data-title="platform-Common/All">Public functions
<!--platform-Common/All--></h2>
<div class="api-item"><a name="awaitPointerEvent-androidx.compose.ui.input.pointer.PointerEventPass-"></a><a name="awaitpointerevent"></a>
<div class="api-name-block">
<div>
<h3 id="awaitPointerEvent(androidx.compose.ui.input.pointer.PointerEventPass)">awaitPointerEvent</h3>
</div>
<div class="api-name-platform-and-metadata">
<div class="api-name-platform-icons"><span class="kotlin-platform" data-title="Common/All">Cmn</span>
<!--platform-Common/All--></div>
</div>
</div>
<pre class="api-signature no-pretty-print">suspend&nbsp;fun&nbsp;<a href="/reference/kotlin/androidx/compose/ui/input/pointer/AwaitPointerEventScope.html#awaitPointerEvent(androidx.compose.ui.input.pointer.PointerEventPass)">awaitPointerEvent</a>(pass:&nbsp;<a href="/reference/kotlin/androidx/compose/ui/input/pointer/PointerEventPass.html">PointerEventPass</a> = PointerEventPass.Main):&nbsp;<a href="/reference/kotlin/androidx/compose/ui/input/pointer/PointerEvent.html">PointerEvent</a></pre>
<p>Suspend until a <code><a href="/reference/kotlin/androidx/compose/ui/input/pointer/PointerEvent.html">PointerEvent</a></code> is reported to the specified input <code><a href="/reference/kotlin/androidx/compose/ui/input/pointer/AwaitPointerEventScope.html#awaitPointerEvent(androidx.compose.ui.input.pointer.PointerEventPass)">pass</a></code>. <code><a href="/reference/kotlin/androidx/compose/ui/input/pointer/AwaitPointerEventScope.html#awaitPointerEvent(androidx.compose.ui.input.pointer.PointerEventPass)">pass</a></code> defaults to <code><a href="/reference/kotlin/androidx/compose/ui/input/pointer/PointerEventPass.html#Main">PointerEventPass.Main</a></code>.</p>
<p><code><a href="/reference/kotlin/androidx/compose/ui/input/pointer/AwaitPointerEventScope.html#awaitPointerEvent(androidx.compose.ui.input.pointer.PointerEventPass)">awaitPointerEvent</a></code> resumes <b>synchronously</b> in the restricted suspension scope. This means that callers can react immediately to input after <code><a href="/reference/kotlin/androidx/compose/ui/input/pointer/AwaitPointerEventScope.html#awaitPointerEvent(androidx.compose.ui.input.pointer.PointerEventPass)">awaitPointerEvent</a></code> returns and affect both the current frame and the next handler or phase of the input processing pipeline. Callers should mutate the returned <code><a href="/reference/kotlin/androidx/compose/ui/input/pointer/PointerEvent.html">PointerEvent</a></code> before awaiting another event to consume aspects of the event before the next stage of input processing runs.</p>
</div>
<div class="api-item"><a name="withTimeout(kotlin.Long, kotlin.coroutines.SuspendFunction1)"></a><a name="withTimeout-kotlin.Long-kotlin.coroutines.SuspendFunction1-"></a><a name="withtimeout"></a>
<div class="api-name-block">
<div>
<h3 id="withTimeout(kotlin.Long,kotlin.coroutines.SuspendFunction1)">withTimeout</h3>
</div>
<div class="api-name-platform-and-metadata">
<div class="api-name-platform-icons"><span class="kotlin-platform" data-title="Common/All">Cmn</span>
<!--platform-Common/All--></div>
</div>
</div>
<pre class="api-signature no-pretty-print">open&nbsp;suspend&nbsp;fun&nbsp;&lt;T&nbsp;:&nbsp;<a href="https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-any/index.html">Any</a>?&gt; <a href="/reference/kotlin/androidx/compose/ui/input/pointer/AwaitPointerEventScope.html#withTimeout(kotlin.Long,kotlin.coroutines.SuspendFunction1)">withTimeout</a>(timeMillis:&nbsp;<a href="https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-long/index.html">Long</a>,&nbsp;block:&nbsp;suspend&nbsp;<a href="/reference/kotlin/androidx/compose/ui/input/pointer/AwaitPointerEventScope.html">AwaitPointerEventScope</a>.() <span style="white-space: nowrap;">-&gt;</span> T):&nbsp;T</pre>
<p>Runs <code><a href="/reference/kotlin/androidx/compose/ui/input/pointer/AwaitPointerEventScope.html#withTimeout(kotlin.Long,kotlin.coroutines.SuspendFunction1)">block</a></code> and returns its results. An <code><a href="/reference/kotlin/androidx/compose/ui/input/pointer/PointerEventTimeoutCancellationException.html">PointerEventTimeoutCancellationException</a></code> is thrown if <code><a href="/reference/kotlin/androidx/compose/ui/input/pointer/AwaitPointerEventScope.html#withTimeout(kotlin.Long,kotlin.coroutines.SuspendFunction1)">timeMillis</a></code> has passed before <code><a href="/reference/kotlin/androidx/compose/ui/input/pointer/AwaitPointerEventScope.html#withTimeout(kotlin.Long,kotlin.coroutines.SuspendFunction1)">block</a></code> completes.</p>
</div>
<div class="api-item"><a name="withTimeoutOrNull(kotlin.Long, kotlin.coroutines.SuspendFunction1)"></a><a name="withTimeoutOrNull-kotlin.Long-kotlin.coroutines.SuspendFunction1-"></a><a name="withtimeoutornull"></a>
<div class="api-name-block">
<div>
<h3 id="withTimeoutOrNull(kotlin.Long,kotlin.coroutines.SuspendFunction1)">withTimeoutOrNull</h3>
</div>
<div class="api-name-platform-and-metadata">
<div class="api-name-platform-icons"><span class="kotlin-platform" data-title="Common/All">Cmn</span>
<!--platform-Common/All--></div>
</div>
</div>
<pre class="api-signature no-pretty-print">open&nbsp;suspend&nbsp;fun&nbsp;&lt;T&nbsp;:&nbsp;<a href="https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-any/index.html">Any</a>?&gt; <a href="/reference/kotlin/androidx/compose/ui/input/pointer/AwaitPointerEventScope.html#withTimeoutOrNull(kotlin.Long,kotlin.coroutines.SuspendFunction1)">withTimeoutOrNull</a>(timeMillis:&nbsp;<a href="https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-long/index.html">Long</a>,&nbsp;block:&nbsp;suspend&nbsp;<a href="/reference/kotlin/androidx/compose/ui/input/pointer/AwaitPointerEventScope.html">AwaitPointerEventScope</a>.() <span style="white-space: nowrap;">-&gt;</span> T):&nbsp;T?</pre>
<p>Runs <code><a href="/reference/kotlin/androidx/compose/ui/input/pointer/AwaitPointerEventScope.html#withTimeoutOrNull(kotlin.Long,kotlin.coroutines.SuspendFunction1)">block</a></code> and returns the result of <code><a href="/reference/kotlin/androidx/compose/ui/input/pointer/AwaitPointerEventScope.html#withTimeoutOrNull(kotlin.Long,kotlin.coroutines.SuspendFunction1)">block</a></code> or <code>null</code> if <code><a href="/reference/kotlin/androidx/compose/ui/input/pointer/AwaitPointerEventScope.html#withTimeoutOrNull(kotlin.Long,kotlin.coroutines.SuspendFunction1)">timeMillis</a></code> has passed before <code><a href="/reference/kotlin/androidx/compose/ui/input/pointer/AwaitPointerEventScope.html#withTimeoutOrNull(kotlin.Long,kotlin.coroutines.SuspendFunction1)">timeMillis</a></code>.</p>
</div>
</div>
</devsite-filter >
<devsite-filter select-el-container-id="platform">
<div class="list">
<h2 data-title="platform-Common/All">Public properties
<!--platform-Common/All--></h2>
<div class="api-item"><a name="getCurrentEvent()"></a><a name="setCurrentEvent()"></a><a name="getCurrentEvent--"></a><a name="setCurrentEvent--"></a>
<div class="api-name-block">
<div>
<h3 id="currentEvent()">currentEvent</h3>
</div>
<div class="api-name-platform-and-metadata">
<div class="api-name-platform-icons"><span class="kotlin-platform" data-title="Common/All">Cmn</span>
<!--platform-Common/All--></div>
</div>
</div>
<pre class="api-signature no-pretty-print">val&nbsp;<a href="/reference/kotlin/androidx/compose/ui/input/pointer/AwaitPointerEventScope.html#currentEvent()">currentEvent</a>:&nbsp;<a href="/reference/kotlin/androidx/compose/ui/input/pointer/PointerEvent.html">PointerEvent</a></pre>
<p>The <code><a href="/reference/kotlin/androidx/compose/ui/input/pointer/PointerEvent.html">PointerEvent</a></code> from the most recent touch event.</p>
</div>
<div class="api-item"><a name="getExtendedTouchPadding()"></a><a name="setExtendedTouchPadding()"></a><a name="getExtendedTouchPadding--"></a><a name="setExtendedTouchPadding--"></a>
<div class="api-name-block">
<div>
<h3 id="extendedTouchPadding()">extendedTouchPadding</h3>
</div>
<div class="api-name-platform-and-metadata">
<div class="api-name-platform-icons"><span class="kotlin-platform" data-title="Common/All">Cmn</span>
<!--platform-Common/All--></div>
</div>
</div>
<pre class="api-signature no-pretty-print">open&nbsp;val&nbsp;<a href="/reference/kotlin/androidx/compose/ui/input/pointer/AwaitPointerEventScope.html#extendedTouchPadding()">extendedTouchPadding</a>:&nbsp;<a href="/reference/kotlin/androidx/compose/ui/geometry/Size.html">Size</a></pre>
</div>
<div class="api-item"><a name="getSize()"></a><a name="setSize()"></a><a name="getSize--"></a><a name="setSize--"></a>
<div class="api-name-block">
<div>
<h3 id="size()">size</h3>
</div>
<div class="api-name-platform-and-metadata">
<div class="api-name-platform-icons"><span class="kotlin-platform" data-title="Common/All">Cmn</span>
<!--platform-Common/All--></div>
</div>
</div>
<pre class="api-signature no-pretty-print">val&nbsp;<a href="/reference/kotlin/androidx/compose/ui/input/pointer/AwaitPointerEventScope.html#size()">size</a>:&nbsp;<a href="/reference/kotlin/androidx/compose/ui/unit/IntSize.html">IntSize</a></pre>
<p>The measured size of the pointer input region. Input events will be reported with a coordinate space of (0, 0) to (size.width, size,height) as the input region, with (0, 0) indicating the upper left corner.</p>
</div>
<div class="api-item"><a name="getViewConfiguration()"></a><a name="setViewConfiguration()"></a><a name="getViewConfiguration--"></a><a name="setViewConfiguration--"></a>
<div class="api-name-block">
<div>
<h3 id="viewConfiguration()">viewConfiguration</h3>
</div>
<div class="api-name-platform-and-metadata">
<div class="api-name-platform-icons"><span class="kotlin-platform" data-title="Common/All">Cmn</span>
<!--platform-Common/All--></div>
</div>
</div>
<pre class="api-signature no-pretty-print">val&nbsp;<a href="/reference/kotlin/androidx/compose/ui/input/pointer/AwaitPointerEventScope.html#viewConfiguration()">viewConfiguration</a>:&nbsp;<a href="/reference/kotlin/androidx/compose/ui/platform/ViewConfiguration.html">ViewConfiguration</a></pre>
<p>The <code><a href="/reference/kotlin/androidx/compose/ui/platform/ViewConfiguration.html">ViewConfiguration</a></code> used to tune gesture detectors.</p>
</div>
</div>
</devsite-filter >
<devsite-filter select-el-container-id="platform">
<div class="list">
<h2 data-title="platform-Common/All">Extension functions
<!--platform-Common/All--></h2>
<div class="api-item"><a name="-androidx.compose.ui.input.pointer.AwaitPointerEventScope-.awaitDragOrCancellation-androidx.compose.ui.input.pointer.PointerId-"></a><a name="awaitdragorcancellation"></a>
<div class="api-name-block">
<div>
<h3 id="(androidx.compose.ui.input.pointer.AwaitPointerEventScope).awaitDragOrCancellation(androidx.compose.ui.input.pointer.PointerId)">awaitDragOrCancellation</h3>
</div>
<div class="api-name-platform-and-metadata">
<div class="api-name-platform-icons"><span class="kotlin-platform" data-title="Common/All">Cmn</span>
<!--platform-Common/All--></div>
</div>
</div>
<pre class="api-signature no-pretty-print">suspend&nbsp;fun&nbsp;<a href="/reference/kotlin/androidx/compose/ui/input/pointer/AwaitPointerEventScope.html">AwaitPointerEventScope</a>.<a href="/reference/kotlin/androidx/compose/ui/input/pointer/AwaitPointerEventScope.html#(androidx.compose.ui.input.pointer.AwaitPointerEventScope).awaitDragOrCancellation(androidx.compose.ui.input.pointer.PointerId)">awaitDragOrCancellation</a>(pointerId:&nbsp;<a href="/reference/kotlin/androidx/compose/ui/input/pointer/PointerId.html">PointerId</a>):&nbsp;<a href="/reference/kotlin/androidx/compose/ui/input/pointer/PointerInputChange.html">PointerInputChange</a>?</pre>
<p>Reads pointer input events until a drag is detected or all pointers are up. When the final pointer is raised, the up event is returned. When a drag event is detected, the drag change will be returned. Note that if <code><a href="/reference/kotlin/androidx/compose/foundation/gestures/package-summary.html#(androidx.compose.ui.input.pointer.AwaitPointerEventScope).awaitDragOrCancellation(androidx.compose.ui.input.pointer.PointerId)">pointerId</a></code> has been raised, another pointer that is down will be used, if available, so the returned <code><a href="/reference/kotlin/androidx/compose/ui/input/pointer/PointerInputChange.html#id()">PointerInputChange.id</a></code> may differ from <code><a href="/reference/kotlin/androidx/compose/foundation/gestures/package-summary.html#(androidx.compose.ui.input.pointer.AwaitPointerEventScope).awaitDragOrCancellation(androidx.compose.ui.input.pointer.PointerId)">pointerId</a></code>. If the position change in the any direction has been consumed by the <code><a href="/reference/kotlin/androidx/compose/ui/input/pointer/PointerEventPass.html#Main">PointerEventPass.Main</a></code> pass, then the drag is considered canceled and <code>null</code> is returned. If <code><a href="/reference/kotlin/androidx/compose/foundation/gestures/package-summary.html#(androidx.compose.ui.input.pointer.AwaitPointerEventScope).awaitDragOrCancellation(androidx.compose.ui.input.pointer.PointerId)">pointerId</a></code> is not down when <code><a href="/reference/kotlin/androidx/compose/foundation/gestures/package-summary.html#(androidx.compose.ui.input.pointer.AwaitPointerEventScope).awaitDragOrCancellation(androidx.compose.ui.input.pointer.PointerId)">awaitDragOrCancellation</a></code> is called, then <code>null</code> is returned.</p>
<p>Example Usage:</p>
<pre class="prettyprint lang-kotlin">
import androidx.compose.foundation.background
import androidx.compose.foundation.gestures.awaitDragOrCancellation
import androidx.compose.foundation.gestures.awaitEachGesture
import androidx.compose.foundation.gestures.awaitFirstDown
import androidx.compose.foundation.gestures.awaitTouchSlopOrCancellation
import androidx.compose.foundation.layout.Box
import androidx.compose.foundation.layout.fillMaxSize
import androidx.compose.foundation.layout.height
import androidx.compose.foundation.layout.offset
import androidx.compose.foundation.layout.size
import androidx.compose.foundation.layout.width
import androidx.compose.runtime.mutableStateOf
import androidx.compose.runtime.remember
import androidx.compose.ui.Modifier
import androidx.compose.ui.geometry.Offset
import androidx.compose.ui.geometry.Size
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.input.pointer.pointerInput
import androidx.compose.ui.input.pointer.positionChange
import androidx.compose.ui.layout.onSizeChanged
import androidx.compose.ui.unit.IntOffset
import androidx.compose.ui.unit.dp
import androidx.compose.ui.unit.toSize
val offsetX = remember { mutableStateOf(0f) }
val offsetY = remember { mutableStateOf(0f) }
var size by remember { mutableStateOf(Size.Zero) }
Box(
Modifier.fillMaxSize()
.onSizeChanged { size = it.toSize() }
) {
Box(
Modifier.offset { IntOffset(offsetX.value.roundToInt(), offsetY.value.roundToInt()) }
.size(50.dp)
.background(Color.Blue)
.pointerInput(Unit) {
awaitEachGesture {
val down = awaitFirstDown()
var change = awaitTouchSlopOrCancellation(down.id) { change, over -&gt;
val original = Offset(offsetX.value, offsetY.value)
val summed = original + over
val newValue = Offset(
x = summed.x.coerceIn(0f, size.width - 50.dp.toPx()),
y = summed.y.coerceIn(0f, size.height - 50.dp.toPx())
)
change.consume()
offsetX.value = newValue.x
offsetY.value = newValue.y
}
while (change != null &amp;&amp; change.pressed) {
change = awaitDragOrCancellation(change.id)
if (change != null &amp;&amp; change.pressed) {
val original = Offset(offsetX.value, offsetY.value)
val summed = original + change.positionChange()
val newValue = Offset(
x = summed.x.coerceIn(0f, size.width - 50.dp.toPx()),
y = summed.y.coerceIn(0f, size.height - 50.dp.toPx())
)
change.consume()
offsetX.value = newValue.x
offsetY.value = newValue.y
}
}
}
}
)
}</pre>
<div class="devsite-table-wrapper">
<table class="responsive">
<colgroup>
<col width="40%">
<col>
</colgroup>
<thead>
<tr>
<th colspan="100%">See also</th>
</tr>
</thead>
<tbody class="list">
<tr>
<td><code><a href="/reference/kotlin/androidx/compose/foundation/gestures/package-summary.html#(androidx.compose.ui.input.pointer.AwaitPointerEventScope).awaitVerticalDragOrCancellation(androidx.compose.ui.input.pointer.PointerId)">awaitVerticalDragOrCancellation</a></code></td>
<td></td>
</tr>
<tr>
<td><code><a href="/reference/kotlin/androidx/compose/foundation/gestures/package-summary.html#(androidx.compose.ui.input.pointer.AwaitPointerEventScope).awaitHorizontalDragOrCancellation(androidx.compose.ui.input.pointer.PointerId)">awaitHorizontalDragOrCancellation</a></code></td>
<td></td>
</tr>
<tr>
<td><code><a href="/reference/kotlin/androidx/compose/foundation/gestures/package-summary.html#(androidx.compose.ui.input.pointer.AwaitPointerEventScope).drag(androidx.compose.ui.input.pointer.PointerId,kotlin.Function1)">drag</a></code></td>
<td></td>
</tr>
</tbody>
</table>
</div>
</div>
<div class="api-item"><a name="-androidx.compose.ui.input.pointer.AwaitPointerEventScope-.awaitHorizontalDragOrCancellation-androidx.compose.ui.input.pointer.PointerId-"></a><a name="awaithorizontaldragorcancellation"></a>
<div class="api-name-block">
<div>
<h3 id="(androidx.compose.ui.input.pointer.AwaitPointerEventScope).awaitHorizontalDragOrCancellation(androidx.compose.ui.input.pointer.PointerId)">awaitHorizontalDragOrCancellation</h3>
</div>
<div class="api-name-platform-and-metadata">
<div class="api-name-platform-icons"><span class="kotlin-platform" data-title="Common/All">Cmn</span>
<!--platform-Common/All--></div>
</div>
</div>
<pre class="api-signature no-pretty-print">suspend&nbsp;fun&nbsp;<a href="/reference/kotlin/androidx/compose/ui/input/pointer/AwaitPointerEventScope.html">AwaitPointerEventScope</a>.<a href="/reference/kotlin/androidx/compose/ui/input/pointer/AwaitPointerEventScope.html#(androidx.compose.ui.input.pointer.AwaitPointerEventScope).awaitHorizontalDragOrCancellation(androidx.compose.ui.input.pointer.PointerId)">awaitHorizontalDragOrCancellation</a>(<br>&nbsp;&nbsp;&nbsp;&nbsp;pointerId:&nbsp;<a href="/reference/kotlin/androidx/compose/ui/input/pointer/PointerId.html">PointerId</a><br>):&nbsp;<a href="/reference/kotlin/androidx/compose/ui/input/pointer/PointerInputChange.html">PointerInputChange</a>?</pre>
<p>Reads pointer input events until a horizontal drag is detected or all pointers are up. When the final pointer is raised, the up event is returned. When a drag event is detected, the drag change will be returned. Note that if <code><a href="/reference/kotlin/androidx/compose/foundation/gestures/package-summary.html#(androidx.compose.ui.input.pointer.AwaitPointerEventScope).awaitHorizontalDragOrCancellation(androidx.compose.ui.input.pointer.PointerId)">pointerId</a></code> has been raised, another pointer that is down will be used, if available, so the returned <code><a href="/reference/kotlin/androidx/compose/ui/input/pointer/PointerInputChange.html#id()">PointerInputChange.id</a></code> may differ from <code><a href="/reference/kotlin/androidx/compose/foundation/gestures/package-summary.html#(androidx.compose.ui.input.pointer.AwaitPointerEventScope).awaitHorizontalDragOrCancellation(androidx.compose.ui.input.pointer.PointerId)">pointerId</a></code>. If the position change has been consumed by the <code><a href="/reference/kotlin/androidx/compose/ui/input/pointer/PointerEventPass.html#Main">PointerEventPass.Main</a></code> pass, then the drag is considered canceled and <code>null</code> is returned. If <code><a href="/reference/kotlin/androidx/compose/foundation/gestures/package-summary.html#(androidx.compose.ui.input.pointer.AwaitPointerEventScope).awaitHorizontalDragOrCancellation(androidx.compose.ui.input.pointer.PointerId)">pointerId</a></code> is not down when <code><a href="/reference/kotlin/androidx/compose/foundation/gestures/package-summary.html#(androidx.compose.ui.input.pointer.AwaitPointerEventScope).awaitHorizontalDragOrCancellation(androidx.compose.ui.input.pointer.PointerId)">awaitHorizontalDragOrCancellation</a></code> is called, then <code>null</code> is returned.</p>
<p>Example Usage:</p>
<pre class="prettyprint lang-kotlin">
import androidx.compose.foundation.background
import androidx.compose.foundation.gestures.awaitEachGesture
import androidx.compose.foundation.gestures.awaitFirstDown
import androidx.compose.foundation.gestures.awaitHorizontalDragOrCancellation
import androidx.compose.foundation.gestures.awaitHorizontalTouchSlopOrCancellation
import androidx.compose.foundation.layout.Box
import androidx.compose.foundation.layout.fillMaxHeight
import androidx.compose.foundation.layout.fillMaxSize
import androidx.compose.foundation.layout.offset
import androidx.compose.foundation.layout.width
import androidx.compose.runtime.mutableStateOf
import androidx.compose.runtime.remember
import androidx.compose.ui.Modifier
import androidx.compose.ui.geometry.Offset
import androidx.compose.ui.geometry.Size
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.input.pointer.pointerInput
import androidx.compose.ui.input.pointer.positionChange
import androidx.compose.ui.layout.onSizeChanged
import androidx.compose.ui.unit.IntOffset
import androidx.compose.ui.unit.dp
val offsetX = remember { mutableStateOf(0f) }
val offsetY = remember { mutableStateOf(0f) }
var width by remember { mutableStateOf(0f) }
Box(
Modifier.fillMaxSize()
.onSizeChanged { width = it.width.toFloat() }
) {
Box(
Modifier.offset { IntOffset(offsetX.value.roundToInt(), offsetY.value.roundToInt()) }
.fillMaxHeight()
.width(50.dp)
.background(Color.Blue)
.pointerInput(Unit) {
awaitEachGesture {
val down = awaitFirstDown()
var change =
awaitHorizontalTouchSlopOrCancellation(down.id) { change, over -&gt;
val originalX = offsetX.value
val newValue =
(originalX + over).coerceIn(0f, width - 50.dp.toPx())
change.consume()
offsetX.value = newValue
}
while (change != null &amp;&amp; change.pressed) {
change = awaitHorizontalDragOrCancellation(change.id)
if (change != null &amp;&amp; change.pressed) {
val originalX = offsetX.value
val newValue = (originalX + change.positionChange().x)
.coerceIn(0f, width - 50.dp.toPx())
change.consume()
offsetX.value = newValue
}
}
}
}
)
}</pre>
<div class="devsite-table-wrapper">
<table class="responsive">
<colgroup>
<col width="40%">
<col>
</colgroup>
<thead>
<tr>
<th colspan="100%">See also</th>
</tr>
</thead>
<tbody class="list">
<tr>
<td><code><a href="/reference/kotlin/androidx/compose/foundation/gestures/package-summary.html#(androidx.compose.ui.input.pointer.AwaitPointerEventScope).horizontalDrag(androidx.compose.ui.input.pointer.PointerId,kotlin.Function1)">horizontalDrag</a></code></td>
<td></td>
</tr>
<tr>
<td><code><a href="/reference/kotlin/androidx/compose/foundation/gestures/package-summary.html#(androidx.compose.ui.input.pointer.AwaitPointerEventScope).awaitVerticalDragOrCancellation(androidx.compose.ui.input.pointer.PointerId)">awaitVerticalDragOrCancellation</a></code></td>
<td></td>
</tr>
<tr>
<td><code><a href="/reference/kotlin/androidx/compose/foundation/gestures/package-summary.html#(androidx.compose.ui.input.pointer.AwaitPointerEventScope).awaitDragOrCancellation(androidx.compose.ui.input.pointer.PointerId)">awaitDragOrCancellation</a></code></td>
<td></td>
</tr>
</tbody>
</table>
</div>
</div>
<div class="api-item"><a name="(androidx.compose.ui.input.pointer.AwaitPointerEventScope).awaitHorizontalTouchSlopOrCancellation(androidx.compose.ui.input.pointer.PointerId, kotlin.Function2)"></a><a name="-androidx.compose.ui.input.pointer.AwaitPointerEventScope-.awaitHorizontalTouchSlopOrCancellation-androidx.compose.ui.input.pointer.PointerId-kotlin.Function2-"></a><a name="awaithorizontaltouchsloporcancellation"></a>
<div class="api-name-block">
<div>
<h3 id="(androidx.compose.ui.input.pointer.AwaitPointerEventScope).awaitHorizontalTouchSlopOrCancellation(androidx.compose.ui.input.pointer.PointerId,kotlin.Function2)">awaitHorizontalTouchSlopOrCancellation</h3>
</div>
<div class="api-name-platform-and-metadata">
<div class="api-name-platform-icons"><span class="kotlin-platform" data-title="Common/All">Cmn</span>
<!--platform-Common/All--></div>
</div>
</div>
<pre class="api-signature no-pretty-print">suspend&nbsp;fun&nbsp;<a href="/reference/kotlin/androidx/compose/ui/input/pointer/AwaitPointerEventScope.html">AwaitPointerEventScope</a>.<a href="/reference/kotlin/androidx/compose/ui/input/pointer/AwaitPointerEventScope.html#(androidx.compose.ui.input.pointer.AwaitPointerEventScope).awaitHorizontalTouchSlopOrCancellation(androidx.compose.ui.input.pointer.PointerId,kotlin.Function2)">awaitHorizontalTouchSlopOrCancellation</a>(<br>&nbsp;&nbsp;&nbsp;&nbsp;pointerId:&nbsp;<a href="/reference/kotlin/androidx/compose/ui/input/pointer/PointerId.html">PointerId</a>,<br>&nbsp;&nbsp;&nbsp;&nbsp;onTouchSlopReached:&nbsp;(change:&nbsp;<a href="/reference/kotlin/androidx/compose/ui/input/pointer/PointerInputChange.html">PointerInputChange</a>, overSlop:&nbsp;<a href="https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-float/index.html">Float</a>) <span style="white-space: nowrap;">-&gt;</span> <a href="https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-unit/index.html">Unit</a><br>):&nbsp;<a href="/reference/kotlin/androidx/compose/ui/input/pointer/PointerInputChange.html">PointerInputChange</a>?</pre>
<p>Waits for horizontal drag motion to pass <code><a href="/reference/kotlin/androidx/compose/ui/platform/ViewConfiguration.html#touchSlop()">touch slop</a></code>, using <code><a href="/reference/kotlin/androidx/compose/foundation/gestures/package-summary.html#(androidx.compose.ui.input.pointer.AwaitPointerEventScope).awaitHorizontalTouchSlopOrCancellation(androidx.compose.ui.input.pointer.PointerId,kotlin.Function2)">pointerId</a></code> as the pointer to examine. If <code><a href="/reference/kotlin/androidx/compose/foundation/gestures/package-summary.html#(androidx.compose.ui.input.pointer.AwaitPointerEventScope).awaitHorizontalTouchSlopOrCancellation(androidx.compose.ui.input.pointer.PointerId,kotlin.Function2)">pointerId</a></code> is raised, another pointer from those that are down will be chosen to lead the gesture, and if none are down, <code>null</code> is returned.</p>
<p><code><a href="/reference/kotlin/androidx/compose/foundation/gestures/package-summary.html#(androidx.compose.ui.input.pointer.AwaitPointerEventScope).awaitHorizontalTouchSlopOrCancellation(androidx.compose.ui.input.pointer.PointerId,kotlin.Function2)">onTouchSlopReached</a></code> is called after <code><a href="/reference/kotlin/androidx/compose/ui/platform/ViewConfiguration.html#touchSlop()">ViewConfiguration.touchSlop</a></code> motion in the horizontal direction with the change that caused the motion beyond touch slop and the pixels beyond touch slop. <code><a href="/reference/kotlin/androidx/compose/foundation/gestures/package-summary.html#(androidx.compose.ui.input.pointer.AwaitPointerEventScope).awaitHorizontalTouchSlopOrCancellation(androidx.compose.ui.input.pointer.PointerId,kotlin.Function2)">onTouchSlopReached</a></code> should consume the position change if it accepts the motion. If it does, then the method returns that <code><a href="/reference/kotlin/androidx/compose/ui/input/pointer/PointerInputChange.html">PointerInputChange</a></code>. If not, touch slop detection will continue. If <code><a href="/reference/kotlin/androidx/compose/foundation/gestures/package-summary.html#(androidx.compose.ui.input.pointer.AwaitPointerEventScope).awaitHorizontalTouchSlopOrCancellation(androidx.compose.ui.input.pointer.PointerId,kotlin.Function2)">pointerId</a></code> is not down when <code><a href="/reference/kotlin/androidx/compose/foundation/gestures/package-summary.html#(androidx.compose.ui.input.pointer.AwaitPointerEventScope).awaitHorizontalTouchSlopOrCancellation(androidx.compose.ui.input.pointer.PointerId,kotlin.Function2)">awaitHorizontalTouchSlopOrCancellation</a></code> is called, then <code>null</code> is returned.</p>
<pre class="prettyprint lang-kotlin">
import androidx.compose.foundation.background
import androidx.compose.foundation.gestures.awaitEachGesture
import androidx.compose.foundation.gestures.awaitFirstDown
import androidx.compose.foundation.gestures.awaitHorizontalDragOrCancellation
import androidx.compose.foundation.gestures.awaitHorizontalTouchSlopOrCancellation
import androidx.compose.foundation.layout.Box
import androidx.compose.foundation.layout.fillMaxHeight
import androidx.compose.foundation.layout.fillMaxSize
import androidx.compose.foundation.layout.offset
import androidx.compose.foundation.layout.width
import androidx.compose.runtime.mutableStateOf
import androidx.compose.runtime.remember
import androidx.compose.ui.Modifier
import androidx.compose.ui.geometry.Offset
import androidx.compose.ui.geometry.Size
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.input.pointer.pointerInput
import androidx.compose.ui.input.pointer.positionChange
import androidx.compose.ui.layout.onSizeChanged
import androidx.compose.ui.unit.IntOffset
import androidx.compose.ui.unit.dp
val offsetX = remember { mutableStateOf(0f) }
val offsetY = remember { mutableStateOf(0f) }
var width by remember { mutableStateOf(0f) }
Box(
Modifier.fillMaxSize()
.onSizeChanged { width = it.width.toFloat() }
) {
Box(
Modifier.offset { IntOffset(offsetX.value.roundToInt(), offsetY.value.roundToInt()) }
.fillMaxHeight()
.width(50.dp)
.background(Color.Blue)
.pointerInput(Unit) {
awaitEachGesture {
val down = awaitFirstDown()
var change =
awaitHorizontalTouchSlopOrCancellation(down.id) { change, over -&gt;
val originalX = offsetX.value
val newValue =
(originalX + over).coerceIn(0f, width - 50.dp.toPx())
change.consume()
offsetX.value = newValue
}
while (change != null &amp;&amp; change.pressed) {
change = awaitHorizontalDragOrCancellation(change.id)
if (change != null &amp;&amp; change.pressed) {
val originalX = offsetX.value
val newValue = (originalX + change.positionChange().x)
.coerceIn(0f, width - 50.dp.toPx())
change.consume()
offsetX.value = newValue
}
}
}
}
)
}</pre>
<div class="devsite-table-wrapper">
<table class="responsive">
<colgroup>
<col width="40%">
<col>
</colgroup>
<thead>
<tr>
<th colspan="100%">Returns</th>
</tr>
</thead>
<tbody class="list">
<tr>
<td><code><a href="/reference/kotlin/androidx/compose/ui/input/pointer/PointerInputChange.html">PointerInputChange</a>?</code></td>
<td>
<p>The <code><a href="/reference/kotlin/androidx/compose/ui/input/pointer/PointerInputChange.html">PointerInputChange</a></code> that was consumed in <code><a href="/reference/kotlin/androidx/compose/foundation/gestures/package-summary.html#(androidx.compose.ui.input.pointer.AwaitPointerEventScope).awaitHorizontalTouchSlopOrCancellation(androidx.compose.ui.input.pointer.PointerId,kotlin.Function2)">onTouchSlopReached</a></code> or <code>null</code> if all pointers are raised before touch slop is detected or another gesture consumed the position change.</p>
<p>Example Usage:</p>
</td>
</tr>
</tbody>
</table>
</div>
<div class="devsite-table-wrapper">
<table class="responsive">
<colgroup>
<col width="40%">
<col>
</colgroup>
<thead>
<tr>
<th colspan="100%">See also</th>
</tr>
</thead>
<tbody class="list">
<tr>
<td><code><a href="/reference/kotlin/androidx/compose/foundation/gestures/package-summary.html#(androidx.compose.ui.input.pointer.AwaitPointerEventScope).awaitVerticalTouchSlopOrCancellation(androidx.compose.ui.input.pointer.PointerId,kotlin.Function2)">awaitVerticalTouchSlopOrCancellation</a></code></td>
<td></td>
</tr>
<tr>
<td><code><a href="/reference/kotlin/androidx/compose/foundation/gestures/package-summary.html#(androidx.compose.ui.input.pointer.AwaitPointerEventScope).awaitTouchSlopOrCancellation(androidx.compose.ui.input.pointer.PointerId,kotlin.Function2)">awaitTouchSlopOrCancellation</a></code></td>
<td></td>
</tr>
</tbody>
</table>
</div>
</div>
<div class="api-item"><a name="-androidx.compose.ui.input.pointer.AwaitPointerEventScope-.awaitLongPressOrCancellation-androidx.compose.ui.input.pointer.PointerId-"></a><a name="awaitlongpressorcancellation"></a>
<div class="api-name-block">
<div>
<h3 id="(androidx.compose.ui.input.pointer.AwaitPointerEventScope).awaitLongPressOrCancellation(androidx.compose.ui.input.pointer.PointerId)">awaitLongPressOrCancellation</h3>
</div>
<div class="api-name-platform-and-metadata">
<div class="api-name-platform-icons"><span class="kotlin-platform" data-title="Common/All">Cmn</span>
<!--platform-Common/All--></div>
</div>
</div>
<pre class="api-signature no-pretty-print">suspend&nbsp;fun&nbsp;<a href="/reference/kotlin/androidx/compose/ui/input/pointer/AwaitPointerEventScope.html">AwaitPointerEventScope</a>.<a href="/reference/kotlin/androidx/compose/ui/input/pointer/AwaitPointerEventScope.html#(androidx.compose.ui.input.pointer.AwaitPointerEventScope).awaitLongPressOrCancellation(androidx.compose.ui.input.pointer.PointerId)">awaitLongPressOrCancellation</a>(<br>&nbsp;&nbsp;&nbsp;&nbsp;pointerId:&nbsp;<a href="/reference/kotlin/androidx/compose/ui/input/pointer/PointerId.html">PointerId</a><br>):&nbsp;<a href="/reference/kotlin/androidx/compose/ui/input/pointer/PointerInputChange.html">PointerInputChange</a>?</pre>
<p>Waits for a long press by examining <code><a href="/reference/kotlin/androidx/compose/foundation/gestures/package-summary.html#(androidx.compose.ui.input.pointer.AwaitPointerEventScope).awaitLongPressOrCancellation(androidx.compose.ui.input.pointer.PointerId)">pointerId</a></code>.</p>
<p>If that <code><a href="/reference/kotlin/androidx/compose/foundation/gestures/package-summary.html#(androidx.compose.ui.input.pointer.AwaitPointerEventScope).awaitLongPressOrCancellation(androidx.compose.ui.input.pointer.PointerId)">pointerId</a></code> is raised (that is, the user lifts their finger), but another finger (<code><a href="/reference/kotlin/androidx/compose/ui/input/pointer/PointerId.html">PointerId</a></code>) is down at that time, another pointer will be chosen as the lead for the gesture, and if none are down, <code>null</code> is returned.</p>
<pre class="prettyprint lang-kotlin">
import androidx.compose.foundation.BorderStroke
import androidx.compose.foundation.background
import androidx.compose.foundation.border
import androidx.compose.foundation.gestures.awaitEachGesture
import androidx.compose.foundation.gestures.awaitFirstDown
import androidx.compose.foundation.gestures.awaitLongPressOrCancellation
import androidx.compose.foundation.layout.Box
import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.fillMaxSize
import androidx.compose.foundation.layout.size
import androidx.compose.foundation.layout.wrapContentSize
import androidx.compose.material.Text
import androidx.compose.runtime.mutableStateOf
import androidx.compose.runtime.remember
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.draw.clipToBounds
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.input.pointer.pointerInput
import androidx.compose.ui.unit.dp
var count by remember { mutableStateOf(0) }
Column {
Text(&quot;Long Press to increase count. Long Press count: $count&quot;)
Box(
Modifier.fillMaxSize()
.wrapContentSize(Alignment.Center)
.size(192.dp)
.pointerInput(Unit) {
awaitEachGesture {
val down = awaitFirstDown(requireUnconsumed = false)
awaitLongPressOrCancellation(down.id)?.let {
count++
}
}
}
.clipToBounds()
.background(Color.Blue)
.border(BorderStroke(2.dp, Color.Black))
)
}</pre>
<div class="devsite-table-wrapper">
<table class="responsive">
<colgroup>
<col width="40%">
<col>
</colgroup>
<thead>
<tr>
<th colspan="100%">Returns</th>
</tr>
</thead>
<tbody class="list">
<tr>
<td><code><a href="/reference/kotlin/androidx/compose/ui/input/pointer/PointerInputChange.html">PointerInputChange</a>?</code></td>
<td>
<p>The latest <code><a href="/reference/kotlin/androidx/compose/ui/input/pointer/PointerInputChange.html">PointerInputChange</a></code> associated with a long press or <code>null</code> if all pointers are raised before a long press is detected or another gesture consumed the change.</p>
<p>Example Usage:</p>
</td>
</tr>
</tbody>
</table>
</div>
</div>
<div class="api-item"><a name="(androidx.compose.ui.input.pointer.AwaitPointerEventScope).awaitTouchSlopOrCancellation(androidx.compose.ui.input.pointer.PointerId, kotlin.Function2)"></a><a name="-androidx.compose.ui.input.pointer.AwaitPointerEventScope-.awaitTouchSlopOrCancellation-androidx.compose.ui.input.pointer.PointerId-kotlin.Function2-"></a><a name="awaittouchsloporcancellation"></a>
<div class="api-name-block">
<div>
<h3 id="(androidx.compose.ui.input.pointer.AwaitPointerEventScope).awaitTouchSlopOrCancellation(androidx.compose.ui.input.pointer.PointerId,kotlin.Function2)">awaitTouchSlopOrCancellation</h3>
</div>
<div class="api-name-platform-and-metadata">
<div class="api-name-platform-icons"><span class="kotlin-platform" data-title="Common/All">Cmn</span>
<!--platform-Common/All--></div>
</div>
</div>
<pre class="api-signature no-pretty-print">suspend&nbsp;fun&nbsp;<a href="/reference/kotlin/androidx/compose/ui/input/pointer/AwaitPointerEventScope.html">AwaitPointerEventScope</a>.<a href="/reference/kotlin/androidx/compose/ui/input/pointer/AwaitPointerEventScope.html#(androidx.compose.ui.input.pointer.AwaitPointerEventScope).awaitTouchSlopOrCancellation(androidx.compose.ui.input.pointer.PointerId,kotlin.Function2)">awaitTouchSlopOrCancellation</a>(<br>&nbsp;&nbsp;&nbsp;&nbsp;pointerId:&nbsp;<a href="/reference/kotlin/androidx/compose/ui/input/pointer/PointerId.html">PointerId</a>,<br>&nbsp;&nbsp;&nbsp;&nbsp;onTouchSlopReached:&nbsp;(change:&nbsp;<a href="/reference/kotlin/androidx/compose/ui/input/pointer/PointerInputChange.html">PointerInputChange</a>, overSlop:&nbsp;<a href="/reference/kotlin/androidx/compose/ui/geometry/Offset.html">Offset</a>) <span style="white-space: nowrap;">-&gt;</span> <a href="https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-unit/index.html">Unit</a><br>):&nbsp;<a href="/reference/kotlin/androidx/compose/ui/input/pointer/PointerInputChange.html">PointerInputChange</a>?</pre>
<p>Waits for drag motion to pass <code><a href="/reference/kotlin/androidx/compose/ui/platform/ViewConfiguration.html#touchSlop()">touch slop</a></code>, using <code><a href="/reference/kotlin/androidx/compose/foundation/gestures/package-summary.html#(androidx.compose.ui.input.pointer.AwaitPointerEventScope).awaitTouchSlopOrCancellation(androidx.compose.ui.input.pointer.PointerId,kotlin.Function2)">pointerId</a></code> as the pointer to examine. If <code><a href="/reference/kotlin/androidx/compose/foundation/gestures/package-summary.html#(androidx.compose.ui.input.pointer.AwaitPointerEventScope).awaitTouchSlopOrCancellation(androidx.compose.ui.input.pointer.PointerId,kotlin.Function2)">pointerId</a></code> is raised, another pointer from those that are down will be chosen to lead the gesture, and if none are down, <code>null</code> is returned. If <code><a href="/reference/kotlin/androidx/compose/foundation/gestures/package-summary.html#(androidx.compose.ui.input.pointer.AwaitPointerEventScope).awaitTouchSlopOrCancellation(androidx.compose.ui.input.pointer.PointerId,kotlin.Function2)">pointerId</a></code> is not down when <code><a href="/reference/kotlin/androidx/compose/foundation/gestures/package-summary.html#(androidx.compose.ui.input.pointer.AwaitPointerEventScope).awaitTouchSlopOrCancellation(androidx.compose.ui.input.pointer.PointerId,kotlin.Function2)">awaitTouchSlopOrCancellation</a></code> is called, then <code>null</code> is returned.</p>
<p><code><a href="/reference/kotlin/androidx/compose/foundation/gestures/package-summary.html#(androidx.compose.ui.input.pointer.AwaitPointerEventScope).awaitTouchSlopOrCancellation(androidx.compose.ui.input.pointer.PointerId,kotlin.Function2)">onTouchSlopReached</a></code> is called after <code><a href="/reference/kotlin/androidx/compose/ui/platform/ViewConfiguration.html#touchSlop()">ViewConfiguration.touchSlop</a></code> motion in the any direction with the change that caused the motion beyond touch slop and the <code><a href="/reference/kotlin/androidx/compose/ui/geometry/Offset.html">Offset</a></code> beyond touch slop that has passed. <code><a href="/reference/kotlin/androidx/compose/foundation/gestures/package-summary.html#(androidx.compose.ui.input.pointer.AwaitPointerEventScope).awaitTouchSlopOrCancellation(androidx.compose.ui.input.pointer.PointerId,kotlin.Function2)">onTouchSlopReached</a></code> should consume the position change if it accepts the motion. If it does, then the method returns that <code><a href="/reference/kotlin/androidx/compose/ui/input/pointer/PointerInputChange.html">PointerInputChange</a></code>. If not, touch slop detection will continue.</p>
<pre class="prettyprint lang-kotlin">
import androidx.compose.foundation.background
import androidx.compose.foundation.gestures.awaitDragOrCancellation
import androidx.compose.foundation.gestures.awaitEachGesture
import androidx.compose.foundation.gestures.awaitFirstDown
import androidx.compose.foundation.gestures.awaitTouchSlopOrCancellation
import androidx.compose.foundation.layout.Box
import androidx.compose.foundation.layout.fillMaxSize
import androidx.compose.foundation.layout.height
import androidx.compose.foundation.layout.offset
import androidx.compose.foundation.layout.size
import androidx.compose.foundation.layout.width
import androidx.compose.runtime.mutableStateOf
import androidx.compose.runtime.remember
import androidx.compose.ui.Modifier
import androidx.compose.ui.geometry.Offset
import androidx.compose.ui.geometry.Size
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.input.pointer.pointerInput
import androidx.compose.ui.input.pointer.positionChange
import androidx.compose.ui.layout.onSizeChanged
import androidx.compose.ui.unit.IntOffset
import androidx.compose.ui.unit.dp
import androidx.compose.ui.unit.toSize
val offsetX = remember { mutableStateOf(0f) }
val offsetY = remember { mutableStateOf(0f) }
var size by remember { mutableStateOf(Size.Zero) }
Box(
Modifier.fillMaxSize()
.onSizeChanged { size = it.toSize() }
) {
Box(
Modifier.offset { IntOffset(offsetX.value.roundToInt(), offsetY.value.roundToInt()) }
.size(50.dp)
.background(Color.Blue)
.pointerInput(Unit) {
awaitEachGesture {
val down = awaitFirstDown()
var change = awaitTouchSlopOrCancellation(down.id) { change, over -&gt;
val original = Offset(offsetX.value, offsetY.value)
val summed = original + over
val newValue = Offset(
x = summed.x.coerceIn(0f, size.width - 50.dp.toPx()),
y = summed.y.coerceIn(0f, size.height - 50.dp.toPx())
)
change.consume()
offsetX.value = newValue.x
offsetY.value = newValue.y
}
while (change != null &amp;&amp; change.pressed) {
change = awaitDragOrCancellation(change.id)
if (change != null &amp;&amp; change.pressed) {
val original = Offset(offsetX.value, offsetY.value)
val summed = original + change.positionChange()
val newValue = Offset(
x = summed.x.coerceIn(0f, size.width - 50.dp.toPx()),
y = summed.y.coerceIn(0f, size.height - 50.dp.toPx())
)
change.consume()
offsetX.value = newValue.x
offsetY.value = newValue.y
}
}
}
}
)
}</pre>
<div class="devsite-table-wrapper">
<table class="responsive">
<colgroup>
<col width="40%">
<col>
</colgroup>
<thead>
<tr>
<th colspan="100%">Returns</th>
</tr>
</thead>
<tbody class="list">
<tr>
<td><code><a href="/reference/kotlin/androidx/compose/ui/input/pointer/PointerInputChange.html">PointerInputChange</a>?</code></td>
<td>
<p>The <code><a href="/reference/kotlin/androidx/compose/ui/input/pointer/PointerInputChange.html">PointerInputChange</a></code> that was consumed in <code><a href="/reference/kotlin/androidx/compose/foundation/gestures/package-summary.html#(androidx.compose.ui.input.pointer.AwaitPointerEventScope).awaitTouchSlopOrCancellation(androidx.compose.ui.input.pointer.PointerId,kotlin.Function2)">onTouchSlopReached</a></code> or <code>null</code> if all pointers are raised before touch slop is detected or another gesture consumed the position change.</p>
<p>Example Usage:</p>
</td>
</tr>
</tbody>
</table>
</div>
<div class="devsite-table-wrapper">
<table class="responsive">
<colgroup>
<col width="40%">
<col>
</colgroup>
<thead>
<tr>
<th colspan="100%">See also</th>
</tr>
</thead>
<tbody class="list">
<tr>
<td><code><a href="/reference/kotlin/androidx/compose/foundation/gestures/package-summary.html#(androidx.compose.ui.input.pointer.AwaitPointerEventScope).awaitHorizontalTouchSlopOrCancellation(androidx.compose.ui.input.pointer.PointerId,kotlin.Function2)">awaitHorizontalTouchSlopOrCancellation</a></code></td>
<td></td>
</tr>
<tr>
<td><code><a href="/reference/kotlin/androidx/compose/foundation/gestures/package-summary.html#(androidx.compose.ui.input.pointer.AwaitPointerEventScope).awaitVerticalTouchSlopOrCancellation(androidx.compose.ui.input.pointer.PointerId,kotlin.Function2)">awaitVerticalTouchSlopOrCancellation</a></code></td>
<td></td>
</tr>
</tbody>
</table>
</div>
</div>
<div class="api-item"><a name="-androidx.compose.ui.input.pointer.AwaitPointerEventScope-.awaitVerticalDragOrCancellation-androidx.compose.ui.input.pointer.PointerId-"></a><a name="awaitverticaldragorcancellation"></a>
<div class="api-name-block">
<div>
<h3 id="(androidx.compose.ui.input.pointer.AwaitPointerEventScope).awaitVerticalDragOrCancellation(androidx.compose.ui.input.pointer.PointerId)">awaitVerticalDragOrCancellation</h3>
</div>
<div class="api-name-platform-and-metadata">
<div class="api-name-platform-icons"><span class="kotlin-platform" data-title="Common/All">Cmn</span>
<!--platform-Common/All--></div>
</div>
</div>
<pre class="api-signature no-pretty-print">suspend&nbsp;fun&nbsp;<a href="/reference/kotlin/androidx/compose/ui/input/pointer/AwaitPointerEventScope.html">AwaitPointerEventScope</a>.<a href="/reference/kotlin/androidx/compose/ui/input/pointer/AwaitPointerEventScope.html#(androidx.compose.ui.input.pointer.AwaitPointerEventScope).awaitVerticalDragOrCancellation(androidx.compose.ui.input.pointer.PointerId)">awaitVerticalDragOrCancellation</a>(<br>&nbsp;&nbsp;&nbsp;&nbsp;pointerId:&nbsp;<a href="/reference/kotlin/androidx/compose/ui/input/pointer/PointerId.html">PointerId</a><br>):&nbsp;<a href="/reference/kotlin/androidx/compose/ui/input/pointer/PointerInputChange.html">PointerInputChange</a>?</pre>
<p>Reads pointer input events until a vertical drag is detected or all pointers are up. When the final pointer is raised, the up event is returned. When a drag event is detected, the drag change will be returned. Note that if <code><a href="/reference/kotlin/androidx/compose/foundation/gestures/package-summary.html#(androidx.compose.ui.input.pointer.AwaitPointerEventScope).awaitVerticalDragOrCancellation(androidx.compose.ui.input.pointer.PointerId)">pointerId</a></code> has been raised, another pointer that is down will be used, if available, so the returned <code><a href="/reference/kotlin/androidx/compose/ui/input/pointer/PointerInputChange.html#id()">PointerInputChange.id</a></code> may differ from <code><a href="/reference/kotlin/androidx/compose/foundation/gestures/package-summary.html#(androidx.compose.ui.input.pointer.AwaitPointerEventScope).awaitVerticalDragOrCancellation(androidx.compose.ui.input.pointer.PointerId)">pointerId</a></code>. If the position change has been consumed by the <code><a href="/reference/kotlin/androidx/compose/ui/input/pointer/PointerEventPass.html#Main">PointerEventPass.Main</a></code> pass, then the drag is considered canceled and <code>null</code> is returned. If <code><a href="/reference/kotlin/androidx/compose/foundation/gestures/package-summary.html#(androidx.compose.ui.input.pointer.AwaitPointerEventScope).awaitVerticalDragOrCancellation(androidx.compose.ui.input.pointer.PointerId)">pointerId</a></code> is not down when <code><a href="/reference/kotlin/androidx/compose/foundation/gestures/package-summary.html#(androidx.compose.ui.input.pointer.AwaitPointerEventScope).awaitVerticalDragOrCancellation(androidx.compose.ui.input.pointer.PointerId)">awaitVerticalDragOrCancellation</a></code> is called, then <code>null</code> is returned.</p>
<p>Example Usage:</p>
<pre class="prettyprint lang-kotlin">
import androidx.compose.foundation.background
import androidx.compose.foundation.gestures.awaitEachGesture
import androidx.compose.foundation.gestures.awaitFirstDown
import androidx.compose.foundation.gestures.awaitVerticalDragOrCancellation
import androidx.compose.foundation.gestures.awaitVerticalTouchSlopOrCancellation
import androidx.compose.foundation.layout.Box
import androidx.compose.foundation.layout.fillMaxSize
import androidx.compose.foundation.layout.fillMaxWidth
import androidx.compose.foundation.layout.height
import androidx.compose.foundation.layout.offset
import androidx.compose.runtime.mutableStateOf
import androidx.compose.runtime.remember
import androidx.compose.ui.Modifier
import androidx.compose.ui.geometry.Offset
import androidx.compose.ui.geometry.Size
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.input.pointer.pointerInput
import androidx.compose.ui.input.pointer.positionChange
import androidx.compose.ui.layout.onSizeChanged
import androidx.compose.ui.unit.IntOffset
import androidx.compose.ui.unit.dp
val offsetX = remember { mutableStateOf(0f) }
val offsetY = remember { mutableStateOf(0f) }
var height by remember { mutableStateOf(0f) }
Box(
Modifier.fillMaxSize()
.onSizeChanged { height = it.height.toFloat() }
) {
Box(
Modifier.offset { IntOffset(offsetX.value.roundToInt(), offsetY.value.roundToInt()) }
.fillMaxWidth()
.height(50.dp)
.background(Color.Blue)
.pointerInput(Unit) {
awaitEachGesture {
val down = awaitFirstDown()
var change =
awaitVerticalTouchSlopOrCancellation(down.id) { change, over -&gt;
val originalY = offsetY.value
val newValue = (originalY + over)
.coerceIn(0f, height - 50.dp.toPx())
change.consume()
offsetY.value = newValue
}
while (change != null &amp;&amp; change.pressed) {
change = awaitVerticalDragOrCancellation(change.id)
if (change != null &amp;&amp; change.pressed) {
val originalY = offsetY.value
val newValue = (originalY + change.positionChange().y)
.coerceIn(0f, height - 50.dp.toPx())
change.consume()
offsetY.value = newValue
}
}
}
}
)
}</pre>
<div class="devsite-table-wrapper">
<table class="responsive">
<colgroup>
<col width="40%">
<col>
</colgroup>
<thead>
<tr>
<th colspan="100%">See also</th>
</tr>
</thead>
<tbody class="list">
<tr>
<td><code><a href="/reference/kotlin/androidx/compose/foundation/gestures/package-summary.html#(androidx.compose.ui.input.pointer.AwaitPointerEventScope).awaitHorizontalDragOrCancellation(androidx.compose.ui.input.pointer.PointerId)">awaitHorizontalDragOrCancellation</a></code></td>
<td></td>
</tr>
<tr>
<td><code><a href="/reference/kotlin/androidx/compose/foundation/gestures/package-summary.html#(androidx.compose.ui.input.pointer.AwaitPointerEventScope).awaitDragOrCancellation(androidx.compose.ui.input.pointer.PointerId)">awaitDragOrCancellation</a></code></td>
<td></td>
</tr>
<tr>
<td><code><a href="/reference/kotlin/androidx/compose/foundation/gestures/package-summary.html#(androidx.compose.ui.input.pointer.AwaitPointerEventScope).verticalDrag(androidx.compose.ui.input.pointer.PointerId,kotlin.Function1)">verticalDrag</a></code></td>
<td></td>
</tr>
</tbody>
</table>
</div>
</div>
<div class="api-item"><a name="(androidx.compose.ui.input.pointer.AwaitPointerEventScope).awaitVerticalTouchSlopOrCancellation(androidx.compose.ui.input.pointer.PointerId, kotlin.Function2)"></a><a name="-androidx.compose.ui.input.pointer.AwaitPointerEventScope-.awaitVerticalTouchSlopOrCancellation-androidx.compose.ui.input.pointer.PointerId-kotlin.Function2-"></a><a name="awaitverticaltouchsloporcancellation"></a>
<div class="api-name-block">
<div>
<h3 id="(androidx.compose.ui.input.pointer.AwaitPointerEventScope).awaitVerticalTouchSlopOrCancellation(androidx.compose.ui.input.pointer.PointerId,kotlin.Function2)">awaitVerticalTouchSlopOrCancellation</h3>
</div>
<div class="api-name-platform-and-metadata">
<div class="api-name-platform-icons"><span class="kotlin-platform" data-title="Common/All">Cmn</span>
<!--platform-Common/All--></div>
</div>
</div>
<pre class="api-signature no-pretty-print">suspend&nbsp;fun&nbsp;<a href="/reference/kotlin/androidx/compose/ui/input/pointer/AwaitPointerEventScope.html">AwaitPointerEventScope</a>.<a href="/reference/kotlin/androidx/compose/ui/input/pointer/AwaitPointerEventScope.html#(androidx.compose.ui.input.pointer.AwaitPointerEventScope).awaitVerticalTouchSlopOrCancellation(androidx.compose.ui.input.pointer.PointerId,kotlin.Function2)">awaitVerticalTouchSlopOrCancellation</a>(<br>&nbsp;&nbsp;&nbsp;&nbsp;pointerId:&nbsp;<a href="/reference/kotlin/androidx/compose/ui/input/pointer/PointerId.html">PointerId</a>,<br>&nbsp;&nbsp;&nbsp;&nbsp;onTouchSlopReached:&nbsp;(change:&nbsp;<a href="/reference/kotlin/androidx/compose/ui/input/pointer/PointerInputChange.html">PointerInputChange</a>, overSlop:&nbsp;<a href="https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-float/index.html">Float</a>) <span style="white-space: nowrap;">-&gt;</span> <a href="https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-unit/index.html">Unit</a><br>):&nbsp;<a href="/reference/kotlin/androidx/compose/ui/input/pointer/PointerInputChange.html">PointerInputChange</a>?</pre>
<p>Waits for vertical drag motion to pass <code><a href="/reference/kotlin/androidx/compose/ui/platform/ViewConfiguration.html#touchSlop()">touch slop</a></code>, using <code><a href="/reference/kotlin/androidx/compose/foundation/gestures/package-summary.html#(androidx.compose.ui.input.pointer.AwaitPointerEventScope).awaitVerticalTouchSlopOrCancellation(androidx.compose.ui.input.pointer.PointerId,kotlin.Function2)">pointerId</a></code> as the pointer to examine. If <code><a href="/reference/kotlin/androidx/compose/foundation/gestures/package-summary.html#(androidx.compose.ui.input.pointer.AwaitPointerEventScope).awaitVerticalTouchSlopOrCancellation(androidx.compose.ui.input.pointer.PointerId,kotlin.Function2)">pointerId</a></code> is raised, another pointer from those that are down will be chosen to lead the gesture, and if none are down, <code>null</code> is returned. If <code><a href="/reference/kotlin/androidx/compose/foundation/gestures/package-summary.html#(androidx.compose.ui.input.pointer.AwaitPointerEventScope).awaitVerticalTouchSlopOrCancellation(androidx.compose.ui.input.pointer.PointerId,kotlin.Function2)">pointerId</a></code> is not down when <code><a href="/reference/kotlin/androidx/compose/foundation/gestures/package-summary.html#(androidx.compose.ui.input.pointer.AwaitPointerEventScope).awaitVerticalTouchSlopOrCancellation(androidx.compose.ui.input.pointer.PointerId,kotlin.Function2)">awaitVerticalTouchSlopOrCancellation</a></code> is called, then <code>null</code> is returned.</p>
<p><code><a href="/reference/kotlin/androidx/compose/foundation/gestures/package-summary.html#(androidx.compose.ui.input.pointer.AwaitPointerEventScope).awaitVerticalTouchSlopOrCancellation(androidx.compose.ui.input.pointer.PointerId,kotlin.Function2)">onTouchSlopReached</a></code> is called after <code><a href="/reference/kotlin/androidx/compose/ui/platform/ViewConfiguration.html#touchSlop()">ViewConfiguration.touchSlop</a></code> motion in the vertical direction with the change that caused the motion beyond touch slop and the pixels beyond touch slop. <code><a href="/reference/kotlin/androidx/compose/foundation/gestures/package-summary.html#(androidx.compose.ui.input.pointer.AwaitPointerEventScope).awaitVerticalTouchSlopOrCancellation(androidx.compose.ui.input.pointer.PointerId,kotlin.Function2)">onTouchSlopReached</a></code> should consume the position change if it accepts the motion. If it does, then the method returns that <code><a href="/reference/kotlin/androidx/compose/ui/input/pointer/PointerInputChange.html">PointerInputChange</a></code>. If not, touch slop detection will continue.</p>
<pre class="prettyprint lang-kotlin">
import androidx.compose.foundation.background
import androidx.compose.foundation.gestures.awaitEachGesture
import androidx.compose.foundation.gestures.awaitFirstDown
import androidx.compose.foundation.gestures.awaitVerticalDragOrCancellation
import androidx.compose.foundation.gestures.awaitVerticalTouchSlopOrCancellation
import androidx.compose.foundation.layout.Box
import androidx.compose.foundation.layout.fillMaxSize
import androidx.compose.foundation.layout.fillMaxWidth
import androidx.compose.foundation.layout.height
import androidx.compose.foundation.layout.offset
import androidx.compose.runtime.mutableStateOf
import androidx.compose.runtime.remember
import androidx.compose.ui.Modifier
import androidx.compose.ui.geometry.Offset
import androidx.compose.ui.geometry.Size
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.input.pointer.pointerInput
import androidx.compose.ui.input.pointer.positionChange
import androidx.compose.ui.layout.onSizeChanged
import androidx.compose.ui.unit.IntOffset
import androidx.compose.ui.unit.dp
val offsetX = remember { mutableStateOf(0f) }
val offsetY = remember { mutableStateOf(0f) }
var height by remember { mutableStateOf(0f) }
Box(
Modifier.fillMaxSize()
.onSizeChanged { height = it.height.toFloat() }
) {
Box(
Modifier.offset { IntOffset(offsetX.value.roundToInt(), offsetY.value.roundToInt()) }
.fillMaxWidth()
.height(50.dp)
.background(Color.Blue)
.pointerInput(Unit) {
awaitEachGesture {
val down = awaitFirstDown()
var change =
awaitVerticalTouchSlopOrCancellation(down.id) { change, over -&gt;
val originalY = offsetY.value
val newValue = (originalY + over)
.coerceIn(0f, height - 50.dp.toPx())
change.consume()
offsetY.value = newValue
}
while (change != null &amp;&amp; change.pressed) {
change = awaitVerticalDragOrCancellation(change.id)
if (change != null &amp;&amp; change.pressed) {
val originalY = offsetY.value
val newValue = (originalY + change.positionChange().y)
.coerceIn(0f, height - 50.dp.toPx())
change.consume()
offsetY.value = newValue
}
}
}
}
)
}</pre>
<div class="devsite-table-wrapper">
<table class="responsive">
<colgroup>
<col width="40%">
<col>
</colgroup>
<thead>
<tr>
<th colspan="100%">Returns</th>
</tr>
</thead>
<tbody class="list">
<tr>
<td><code><a href="/reference/kotlin/androidx/compose/ui/input/pointer/PointerInputChange.html">PointerInputChange</a>?</code></td>
<td>
<p>The <code><a href="/reference/kotlin/androidx/compose/ui/input/pointer/PointerInputChange.html">PointerInputChange</a></code> that was consumed in <code><a href="/reference/kotlin/androidx/compose/foundation/gestures/package-summary.html#(androidx.compose.ui.input.pointer.AwaitPointerEventScope).awaitVerticalTouchSlopOrCancellation(androidx.compose.ui.input.pointer.PointerId,kotlin.Function2)">onTouchSlopReached</a></code> or <code>null</code> if all pointers are raised before touch slop is detected or another gesture consumed the position change.</p>
<p>Example Usage:</p>
</td>
</tr>
</tbody>
</table>
</div>
<div class="devsite-table-wrapper">
<table class="responsive">
<colgroup>
<col width="40%">
<col>
</colgroup>
<thead>
<tr>
<th colspan="100%">See also</th>
</tr>
</thead>
<tbody class="list">
<tr>
<td><code><a href="/reference/kotlin/androidx/compose/foundation/gestures/package-summary.html#(androidx.compose.ui.input.pointer.AwaitPointerEventScope).awaitHorizontalTouchSlopOrCancellation(androidx.compose.ui.input.pointer.PointerId,kotlin.Function2)">awaitHorizontalTouchSlopOrCancellation</a></code></td>
<td></td>
</tr>
<tr>
<td><code><a href="/reference/kotlin/androidx/compose/foundation/gestures/package-summary.html#(androidx.compose.ui.input.pointer.AwaitPointerEventScope).awaitTouchSlopOrCancellation(androidx.compose.ui.input.pointer.PointerId,kotlin.Function2)">awaitTouchSlopOrCancellation</a></code></td>
<td></td>
</tr>
</tbody>
</table>
</div>
</div>
<div class="api-item"><a name="(androidx.compose.ui.input.pointer.AwaitPointerEventScope).drag(androidx.compose.ui.input.pointer.PointerId, kotlin.Function1)"></a><a name="-androidx.compose.ui.input.pointer.AwaitPointerEventScope-.drag-androidx.compose.ui.input.pointer.PointerId-kotlin.Function1-"></a><a name="drag"></a>
<div class="api-name-block">
<div>
<h3 id="(androidx.compose.ui.input.pointer.AwaitPointerEventScope).drag(androidx.compose.ui.input.pointer.PointerId,kotlin.Function1)">drag</h3>
</div>
<div class="api-name-platform-and-metadata">
<div class="api-name-platform-icons"><span class="kotlin-platform" data-title="Common/All">Cmn</span>
<!--platform-Common/All--></div>
</div>
</div>
<pre class="api-signature no-pretty-print">suspend&nbsp;fun&nbsp;<a href="/reference/kotlin/androidx/compose/ui/input/pointer/AwaitPointerEventScope.html">AwaitPointerEventScope</a>.<a href="/reference/kotlin/androidx/compose/ui/input/pointer/AwaitPointerEventScope.html#(androidx.compose.ui.input.pointer.AwaitPointerEventScope).drag(androidx.compose.ui.input.pointer.PointerId,kotlin.Function1)">drag</a>(<br>&nbsp;&nbsp;&nbsp;&nbsp;pointerId:&nbsp;<a href="/reference/kotlin/androidx/compose/ui/input/pointer/PointerId.html">PointerId</a>,<br>&nbsp;&nbsp;&nbsp;&nbsp;onDrag:&nbsp;(<a href="/reference/kotlin/androidx/compose/ui/input/pointer/PointerInputChange.html">PointerInputChange</a>) <span style="white-space: nowrap;">-&gt;</span> <a href="https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-unit/index.html">Unit</a><br>):&nbsp;<a href="https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-boolean/index.html">Boolean</a></pre>
<p>Reads position change events for <code><a href="/reference/kotlin/androidx/compose/foundation/gestures/package-summary.html#(androidx.compose.ui.input.pointer.AwaitPointerEventScope).drag(androidx.compose.ui.input.pointer.PointerId,kotlin.Function1)">pointerId</a></code> and calls <code><a href="/reference/kotlin/androidx/compose/foundation/gestures/package-summary.html#(androidx.compose.ui.input.pointer.AwaitPointerEventScope).drag(androidx.compose.ui.input.pointer.PointerId,kotlin.Function1)">onDrag</a></code> for every change in position. If <code><a href="/reference/kotlin/androidx/compose/foundation/gestures/package-summary.html#(androidx.compose.ui.input.pointer.AwaitPointerEventScope).drag(androidx.compose.ui.input.pointer.PointerId,kotlin.Function1)">pointerId</a></code> is raised, a new pointer is chosen from those that are down and if none exist, the method returns. This does not wait for touch slop.</p>
<pre class="prettyprint lang-kotlin">
import androidx.compose.foundation.background
import androidx.compose.foundation.gestures.awaitEachGesture
import androidx.compose.foundation.gestures.awaitFirstDown
import androidx.compose.foundation.gestures.awaitTouchSlopOrCancellation
import androidx.compose.foundation.gestures.drag
import androidx.compose.foundation.layout.Box
import androidx.compose.foundation.layout.fillMaxSize
import androidx.compose.foundation.layout.height
import androidx.compose.foundation.layout.offset
import androidx.compose.foundation.layout.size
import androidx.compose.foundation.layout.width
import androidx.compose.runtime.mutableStateOf
import androidx.compose.runtime.remember
import androidx.compose.ui.Modifier
import androidx.compose.ui.geometry.Offset
import androidx.compose.ui.geometry.Size
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.input.pointer.pointerInput
import androidx.compose.ui.input.pointer.positionChange
import androidx.compose.ui.layout.onSizeChanged
import androidx.compose.ui.unit.IntOffset
import androidx.compose.ui.unit.dp
import androidx.compose.ui.unit.toSize
val offsetX = remember { mutableStateOf(0f) }
val offsetY = remember { mutableStateOf(0f) }
var size by remember { mutableStateOf(Size.Zero) }
Box(
Modifier.fillMaxSize()
.onSizeChanged { size = it.toSize() }
) {
Box(
Modifier.offset { IntOffset(offsetX.value.roundToInt(), offsetY.value.roundToInt()) }
.size(50.dp)
.background(Color.Blue)
.pointerInput(Unit) {
awaitEachGesture {
val down = awaitFirstDown()
val change = awaitTouchSlopOrCancellation(down.id) { change, over -&gt;
val original = Offset(offsetX.value, offsetY.value)
val summed = original + over
val newValue = Offset(
x = summed.x.coerceIn(0f, size.width - 50.dp.toPx()),
y = summed.y.coerceIn(0f, size.height - 50.dp.toPx())
)
change.consume()
offsetX.value = newValue.x
offsetY.value = newValue.y
}
if (change != null) {
drag(change.id) {
val original = Offset(offsetX.value, offsetY.value)
val summed = original + it.positionChange()
val newValue = Offset(
x = summed.x.coerceIn(0f, size.width - 50.dp.toPx()),
y = summed.y.coerceIn(0f, size.height - 50.dp.toPx())
)
it.consume()
offsetX.value = newValue.x
offsetY.value = newValue.y
}
}
}
}
)
}</pre>
<div class="devsite-table-wrapper">
<table class="responsive">
<colgroup>
<col width="40%">
<col>
</colgroup>
<thead>
<tr>
<th colspan="100%">Returns</th>
</tr>
</thead>
<tbody class="list">
<tr>
<td><code><a href="https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-boolean/index.html">Boolean</a></code></td>
<td>
<p><code>true</code> if the drag completed normally or <code>false</code> if the drag motion was canceled by another gesture detector consuming position change events.</p>
<p>Example Usage:</p>
</td>
</tr>
</tbody>
</table>
</div>
<div class="devsite-table-wrapper">
<table class="responsive">
<colgroup>
<col width="40%">
<col>
</colgroup>
<thead>
<tr>
<th colspan="100%">See also</th>
</tr>
</thead>
<tbody class="list">
<tr>
<td><code><a href="/reference/kotlin/androidx/compose/foundation/gestures/package-summary.html#(androidx.compose.ui.input.pointer.AwaitPointerEventScope).awaitTouchSlopOrCancellation(androidx.compose.ui.input.pointer.PointerId,kotlin.Function2)">awaitTouchSlopOrCancellation</a></code></td>
<td></td>
</tr>
<tr>
<td><code><a href="/reference/kotlin/androidx/compose/foundation/gestures/package-summary.html#(androidx.compose.ui.input.pointer.AwaitPointerEventScope).awaitDragOrCancellation(androidx.compose.ui.input.pointer.PointerId)">awaitDragOrCancellation</a></code></td>
<td></td>
</tr>
<tr>
<td><code><a href="/reference/kotlin/androidx/compose/foundation/gestures/package-summary.html#(androidx.compose.ui.input.pointer.AwaitPointerEventScope).horizontalDrag(androidx.compose.ui.input.pointer.PointerId,kotlin.Function1)">horizontalDrag</a></code></td>
<td></td>
</tr>
<tr>
<td><code><a href="/reference/kotlin/androidx/compose/foundation/gestures/package-summary.html#(androidx.compose.ui.input.pointer.AwaitPointerEventScope).verticalDrag(androidx.compose.ui.input.pointer.PointerId,kotlin.Function1)">verticalDrag</a></code></td>
<td></td>
</tr>
</tbody>
</table>
</div>
</div>
<div class="api-item"><a name="(androidx.compose.ui.input.pointer.AwaitPointerEventScope).horizontalDrag(androidx.compose.ui.input.pointer.PointerId, kotlin.Function1)"></a><a name="-androidx.compose.ui.input.pointer.AwaitPointerEventScope-.horizontalDrag-androidx.compose.ui.input.pointer.PointerId-kotlin.Function1-"></a><a name="horizontaldrag"></a>
<div class="api-name-block">
<div>
<h3 id="(androidx.compose.ui.input.pointer.AwaitPointerEventScope).horizontalDrag(androidx.compose.ui.input.pointer.PointerId,kotlin.Function1)">horizontalDrag</h3>
</div>
<div class="api-name-platform-and-metadata">
<div class="api-name-platform-icons"><span class="kotlin-platform" data-title="Common/All">Cmn</span>
<!--platform-Common/All--></div>
</div>
</div>
<pre class="api-signature no-pretty-print">suspend&nbsp;fun&nbsp;<a href="/reference/kotlin/androidx/compose/ui/input/pointer/AwaitPointerEventScope.html">AwaitPointerEventScope</a>.<a href="/reference/kotlin/androidx/compose/ui/input/pointer/AwaitPointerEventScope.html#(androidx.compose.ui.input.pointer.AwaitPointerEventScope).horizontalDrag(androidx.compose.ui.input.pointer.PointerId,kotlin.Function1)">horizontalDrag</a>(<br>&nbsp;&nbsp;&nbsp;&nbsp;pointerId:&nbsp;<a href="/reference/kotlin/androidx/compose/ui/input/pointer/PointerId.html">PointerId</a>,<br>&nbsp;&nbsp;&nbsp;&nbsp;onDrag:&nbsp;(<a href="/reference/kotlin/androidx/compose/ui/input/pointer/PointerInputChange.html">PointerInputChange</a>) <span style="white-space: nowrap;">-&gt;</span> <a href="https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-unit/index.html">Unit</a><br>):&nbsp;<a href="https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-boolean/index.html">Boolean</a></pre>
<p>Reads horizontal position change events for <code><a href="/reference/kotlin/androidx/compose/foundation/gestures/package-summary.html#(androidx.compose.ui.input.pointer.AwaitPointerEventScope).horizontalDrag(androidx.compose.ui.input.pointer.PointerId,kotlin.Function1)">pointerId</a></code> and calls <code><a href="/reference/kotlin/androidx/compose/foundation/gestures/package-summary.html#(androidx.compose.ui.input.pointer.AwaitPointerEventScope).horizontalDrag(androidx.compose.ui.input.pointer.PointerId,kotlin.Function1)">onDrag</a></code> for every change in position. If <code><a href="/reference/kotlin/androidx/compose/foundation/gestures/package-summary.html#(androidx.compose.ui.input.pointer.AwaitPointerEventScope).horizontalDrag(androidx.compose.ui.input.pointer.PointerId,kotlin.Function1)">pointerId</a></code> is raised, a new pointer is chosen from those that are down and if none exist, the method returns. This does not wait for touch slop.</p>
<p>Example Usage:</p>
<pre class="prettyprint lang-kotlin">
import androidx.compose.foundation.background
import androidx.compose.foundation.gestures.awaitEachGesture
import androidx.compose.foundation.gestures.awaitFirstDown
import androidx.compose.foundation.gestures.awaitHorizontalTouchSlopOrCancellation
import androidx.compose.foundation.gestures.horizontalDrag
import androidx.compose.foundation.layout.Box
import androidx.compose.foundation.layout.fillMaxHeight
import androidx.compose.foundation.layout.fillMaxSize
import androidx.compose.foundation.layout.offset
import androidx.compose.foundation.layout.width
import androidx.compose.runtime.mutableStateOf
import androidx.compose.runtime.remember
import androidx.compose.ui.Modifier
import androidx.compose.ui.geometry.Offset
import androidx.compose.ui.geometry.Size
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.input.pointer.pointerInput
import androidx.compose.ui.input.pointer.positionChange
import androidx.compose.ui.layout.onSizeChanged
import androidx.compose.ui.unit.IntOffset
import androidx.compose.ui.unit.dp
val offsetX = remember { mutableStateOf(0f) }
val offsetY = remember { mutableStateOf(0f) }
var width by remember { mutableStateOf(0f) }
Box(
Modifier.fillMaxSize()
.onSizeChanged { width = it.width.toFloat() }
) {
Box(
Modifier.offset { IntOffset(offsetX.value.roundToInt(), offsetY.value.roundToInt()) }
.fillMaxHeight()
.width(50.dp)
.background(Color.Blue)
.pointerInput(Unit) {
awaitEachGesture {
val down = awaitFirstDown()
val change =
awaitHorizontalTouchSlopOrCancellation(down.id) { change, over -&gt;
val originalX = offsetX.value
val newValue =
(originalX + over).coerceIn(0f, width - 50.dp.toPx())
change.consume()
offsetX.value = newValue
}
if (change != null) {
horizontalDrag(change.id) {
val originalX = offsetX.value
val newValue = (originalX + it.positionChange().x)
.coerceIn(0f, width - 50.dp.toPx())
it.consume()
offsetX.value = newValue
}
}
}
}
)
}</pre>
<div class="devsite-table-wrapper">
<table class="responsive">
<colgroup>
<col width="40%">
<col>
</colgroup>
<thead>
<tr>
<th colspan="100%">See also</th>
</tr>
</thead>
<tbody class="list">
<tr>
<td><code><a href="/reference/kotlin/androidx/compose/foundation/gestures/package-summary.html#(androidx.compose.ui.input.pointer.AwaitPointerEventScope).awaitHorizontalTouchSlopOrCancellation(androidx.compose.ui.input.pointer.PointerId,kotlin.Function2)">awaitHorizontalTouchSlopOrCancellation</a></code></td>
<td></td>
</tr>
<tr>
<td><code><a href="/reference/kotlin/androidx/compose/foundation/gestures/package-summary.html#(androidx.compose.ui.input.pointer.AwaitPointerEventScope).awaitDragOrCancellation(androidx.compose.ui.input.pointer.PointerId)">awaitDragOrCancellation</a></code></td>
<td></td>
</tr>
<tr>
<td><code><a href="/reference/kotlin/androidx/compose/foundation/gestures/package-summary.html#(androidx.compose.ui.input.pointer.AwaitPointerEventScope).verticalDrag(androidx.compose.ui.input.pointer.PointerId,kotlin.Function1)">verticalDrag</a></code></td>
<td></td>
</tr>
<tr>
<td><code><a href="/reference/kotlin/androidx/compose/foundation/gestures/package-summary.html#(androidx.compose.ui.input.pointer.AwaitPointerEventScope).drag(androidx.compose.ui.input.pointer.PointerId,kotlin.Function1)">drag</a></code></td>
<td></td>
</tr>
</tbody>
</table>
</div>
</div>
<div class="api-item"><a name="(androidx.compose.ui.input.pointer.AwaitPointerEventScope).verticalDrag(androidx.compose.ui.input.pointer.PointerId, kotlin.Function1)"></a><a name="-androidx.compose.ui.input.pointer.AwaitPointerEventScope-.verticalDrag-androidx.compose.ui.input.pointer.PointerId-kotlin.Function1-"></a><a name="verticaldrag"></a>
<div class="api-name-block">
<div>
<h3 id="(androidx.compose.ui.input.pointer.AwaitPointerEventScope).verticalDrag(androidx.compose.ui.input.pointer.PointerId,kotlin.Function1)">verticalDrag</h3>
</div>
<div class="api-name-platform-and-metadata">
<div class="api-name-platform-icons"><span class="kotlin-platform" data-title="Common/All">Cmn</span>
<!--platform-Common/All--></div>
</div>
</div>
<pre class="api-signature no-pretty-print">suspend&nbsp;fun&nbsp;<a href="/reference/kotlin/androidx/compose/ui/input/pointer/AwaitPointerEventScope.html">AwaitPointerEventScope</a>.<a href="/reference/kotlin/androidx/compose/ui/input/pointer/AwaitPointerEventScope.html#(androidx.compose.ui.input.pointer.AwaitPointerEventScope).verticalDrag(androidx.compose.ui.input.pointer.PointerId,kotlin.Function1)">verticalDrag</a>(<br>&nbsp;&nbsp;&nbsp;&nbsp;pointerId:&nbsp;<a href="/reference/kotlin/androidx/compose/ui/input/pointer/PointerId.html">PointerId</a>,<br>&nbsp;&nbsp;&nbsp;&nbsp;onDrag:&nbsp;(<a href="/reference/kotlin/androidx/compose/ui/input/pointer/PointerInputChange.html">PointerInputChange</a>) <span style="white-space: nowrap;">-&gt;</span> <a href="https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-unit/index.html">Unit</a><br>):&nbsp;<a href="https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-boolean/index.html">Boolean</a></pre>
<p>Reads vertical position change events for <code><a href="/reference/kotlin/androidx/compose/foundation/gestures/package-summary.html#(androidx.compose.ui.input.pointer.AwaitPointerEventScope).verticalDrag(androidx.compose.ui.input.pointer.PointerId,kotlin.Function1)">pointerId</a></code> and calls <code><a href="/reference/kotlin/androidx/compose/foundation/gestures/package-summary.html#(androidx.compose.ui.input.pointer.AwaitPointerEventScope).verticalDrag(androidx.compose.ui.input.pointer.PointerId,kotlin.Function1)">onDrag</a></code> for every change in position. If <code><a href="/reference/kotlin/androidx/compose/foundation/gestures/package-summary.html#(androidx.compose.ui.input.pointer.AwaitPointerEventScope).verticalDrag(androidx.compose.ui.input.pointer.PointerId,kotlin.Function1)">pointerId</a></code> is raised, a new pointer is chosen from those that are down and if none exist, the method returns. This does not wait for touch slop</p>
<pre class="prettyprint lang-kotlin">
import androidx.compose.foundation.background
import androidx.compose.foundation.gestures.awaitEachGesture
import androidx.compose.foundation.gestures.awaitFirstDown
import androidx.compose.foundation.gestures.awaitVerticalTouchSlopOrCancellation
import androidx.compose.foundation.gestures.verticalDrag
import androidx.compose.foundation.layout.Box
import androidx.compose.foundation.layout.fillMaxSize
import androidx.compose.foundation.layout.fillMaxWidth
import androidx.compose.foundation.layout.height
import androidx.compose.foundation.layout.offset
import androidx.compose.runtime.mutableStateOf
import androidx.compose.runtime.remember
import androidx.compose.ui.Modifier
import androidx.compose.ui.geometry.Offset
import androidx.compose.ui.geometry.Size
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.input.pointer.pointerInput
import androidx.compose.ui.input.pointer.positionChange
import androidx.compose.ui.layout.onSizeChanged
import androidx.compose.ui.unit.IntOffset
import androidx.compose.ui.unit.dp
val offsetX = remember { mutableStateOf(0f) }
val offsetY = remember { mutableStateOf(0f) }
var height by remember { mutableStateOf(0f) }
Box(
Modifier.fillMaxSize()
.onSizeChanged { height = it.height.toFloat() }
) {
Box(
Modifier.offset { IntOffset(offsetX.value.roundToInt(), offsetY.value.roundToInt()) }
.fillMaxWidth()
.height(50.dp)
.background(Color.Blue)
.pointerInput(Unit) {
awaitEachGesture {
val down = awaitFirstDown()
val change =
awaitVerticalTouchSlopOrCancellation(down.id) { change, over -&gt;
val originalY = offsetY.value
val newValue = (originalY + over)
.coerceIn(0f, height - 50.dp.toPx())
change.consume()
offsetY.value = newValue
}
if (change != null) {
verticalDrag(change.id) {
val originalY = offsetY.value
val newValue = (originalY + it.positionChange().y)
.coerceIn(0f, height - 50.dp.toPx())
it.consume()
offsetY.value = newValue
}
}
}
}
)
}</pre>
<div class="devsite-table-wrapper">
<table class="responsive">
<colgroup>
<col width="40%">
<col>
</colgroup>
<thead>
<tr>
<th colspan="100%">Returns</th>
</tr>
</thead>
<tbody class="list">
<tr>
<td><code><a href="https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-boolean/index.html">Boolean</a></code></td>
<td>
<p><code>true</code> if the vertical drag completed normally or <code>false</code> if the drag motion was canceled by another gesture detector consuming position change events.</p>
<p>Example Usage:</p>
</td>
</tr>
</tbody>
</table>
</div>
<div class="devsite-table-wrapper">
<table class="responsive">
<colgroup>
<col width="40%">
<col>
</colgroup>
<thead>
<tr>
<th colspan="100%">See also</th>
</tr>
</thead>
<tbody class="list">
<tr>
<td><code><a href="/reference/kotlin/androidx/compose/foundation/gestures/package-summary.html#(androidx.compose.ui.input.pointer.AwaitPointerEventScope).awaitVerticalTouchSlopOrCancellation(androidx.compose.ui.input.pointer.PointerId,kotlin.Function2)">awaitVerticalTouchSlopOrCancellation</a></code></td>
<td></td>
</tr>
<tr>
<td><code><a href="/reference/kotlin/androidx/compose/foundation/gestures/package-summary.html#(androidx.compose.ui.input.pointer.AwaitPointerEventScope).awaitVerticalDragOrCancellation(androidx.compose.ui.input.pointer.PointerId)">awaitVerticalDragOrCancellation</a></code></td>
<td></td>
</tr>
<tr>
<td><code><a href="/reference/kotlin/androidx/compose/foundation/gestures/package-summary.html#(androidx.compose.ui.input.pointer.AwaitPointerEventScope).horizontalDrag(androidx.compose.ui.input.pointer.PointerId,kotlin.Function1)">horizontalDrag</a></code></td>
<td></td>
</tr>
<tr>
<td><code><a href="/reference/kotlin/androidx/compose/foundation/gestures/package-summary.html#(androidx.compose.ui.input.pointer.AwaitPointerEventScope).drag(androidx.compose.ui.input.pointer.PointerId,kotlin.Function1)">drag</a></code></td>
<td></td>
</tr>
</tbody>
</table>
</div>
</div>
<div class="api-item"><a name="(androidx.compose.ui.input.pointer.AwaitPointerEventScope).awaitFirstDown(kotlin.Boolean, androidx.compose.ui.input.pointer.PointerEventPass)"></a><a name="-androidx.compose.ui.input.pointer.AwaitPointerEventScope-.awaitFirstDown-kotlin.Boolean-androidx.compose.ui.input.pointer.PointerEventPass-"></a><a name="awaitfirstdown"></a>
<div class="api-name-block">
<div>
<h3 id="(androidx.compose.ui.input.pointer.AwaitPointerEventScope).awaitFirstDown(kotlin.Boolean,androidx.compose.ui.input.pointer.PointerEventPass)">awaitFirstDown</h3>
</div>
<div class="api-name-platform-and-metadata">
<div class="api-name-platform-icons"><span class="kotlin-platform" data-title="Common/All">Cmn</span>
<!--platform-Common/All--></div>
</div>
</div>
<pre class="api-signature no-pretty-print">suspend&nbsp;fun&nbsp;<a href="/reference/kotlin/androidx/compose/ui/input/pointer/AwaitPointerEventScope.html">AwaitPointerEventScope</a>.<a href="/reference/kotlin/androidx/compose/ui/input/pointer/AwaitPointerEventScope.html#(androidx.compose.ui.input.pointer.AwaitPointerEventScope).awaitFirstDown(kotlin.Boolean,androidx.compose.ui.input.pointer.PointerEventPass)">awaitFirstDown</a>(<br>&nbsp;&nbsp;&nbsp;&nbsp;requireUnconsumed:&nbsp;<a href="https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-boolean/index.html">Boolean</a> = true,<br>&nbsp;&nbsp;&nbsp;&nbsp;pass:&nbsp;<a href="/reference/kotlin/androidx/compose/ui/input/pointer/PointerEventPass.html">PointerEventPass</a> = PointerEventPass.Main<br>):&nbsp;<a href="/reference/kotlin/androidx/compose/ui/input/pointer/PointerInputChange.html">PointerInputChange</a></pre>
<p>Reads events until the first down is received in the given <code><a href="/reference/kotlin/androidx/compose/foundation/gestures/package-summary.html#(androidx.compose.ui.input.pointer.AwaitPointerEventScope).awaitFirstDown(kotlin.Boolean,androidx.compose.ui.input.pointer.PointerEventPass)">pass</a></code>. If <code><a href="/reference/kotlin/androidx/compose/foundation/gestures/package-summary.html#(androidx.compose.ui.input.pointer.AwaitPointerEventScope).awaitFirstDown(kotlin.Boolean,androidx.compose.ui.input.pointer.PointerEventPass)">requireUnconsumed</a></code> is <code>true</code> and the first down is already consumed in the pass, that gesture is ignored.</p>
</div>
<div class="api-item"><a name="-androidx.compose.ui.input.pointer.AwaitPointerEventScope-.waitForUpOrCancellation-androidx.compose.ui.input.pointer.PointerEventPass-"></a><a name="waitforuporcancellation"></a>
<div class="api-name-block">
<div>
<h3 id="(androidx.compose.ui.input.pointer.AwaitPointerEventScope).waitForUpOrCancellation(androidx.compose.ui.input.pointer.PointerEventPass)">waitForUpOrCancellation</h3>
</div>
<div class="api-name-platform-and-metadata">
<div class="api-name-platform-icons"><span class="kotlin-platform" data-title="Common/All">Cmn</span>
<!--platform-Common/All--></div>
</div>
</div>
<pre class="api-signature no-pretty-print">suspend&nbsp;fun&nbsp;<a href="/reference/kotlin/androidx/compose/ui/input/pointer/AwaitPointerEventScope.html">AwaitPointerEventScope</a>.<a href="/reference/kotlin/androidx/compose/ui/input/pointer/AwaitPointerEventScope.html#(androidx.compose.ui.input.pointer.AwaitPointerEventScope).waitForUpOrCancellation(androidx.compose.ui.input.pointer.PointerEventPass)">waitForUpOrCancellation</a>(<br>&nbsp;&nbsp;&nbsp;&nbsp;pass:&nbsp;<a href="/reference/kotlin/androidx/compose/ui/input/pointer/PointerEventPass.html">PointerEventPass</a> = PointerEventPass.Main<br>):&nbsp;<a href="/reference/kotlin/androidx/compose/ui/input/pointer/PointerInputChange.html">PointerInputChange</a>?</pre>
<p>Reads events in the given <code><a href="/reference/kotlin/androidx/compose/foundation/gestures/package-summary.html#(androidx.compose.ui.input.pointer.AwaitPointerEventScope).waitForUpOrCancellation(androidx.compose.ui.input.pointer.PointerEventPass)">pass</a></code> until all pointers are up or the gesture was canceled. The gesture is considered canceled when a pointer leaves the event region, a position change has been consumed or a pointer down change event was already consumed in the given pass. If the gesture was not canceled, the final up change is returned or <code>null</code> if the event was canceled.</p>
</div>
</div>
</devsite-filter >
</body>
</html>