Skip to content

Commit 4fe3000

Browse files
committed
fix multi fingers fails detect up point event
1 parent b6c81d4 commit 4fe3000

File tree

2 files changed

+10
-15
lines changed

2 files changed

+10
-15
lines changed

ptr-compose/src/main/java/wtf/s1/ui/nsptr/compose/NSPtrGesture.kt

Lines changed: 8 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -5,24 +5,19 @@ import androidx.compose.foundation.gestures.forEachGesture
55
import androidx.compose.ui.geometry.Offset
66
import androidx.compose.ui.input.pointer.*
77
import androidx.compose.ui.util.fastAll
8-
import androidx.compose.ui.util.fastAny
9-
import kotlinx.coroutines.coroutineScope
10-
118

129
suspend fun PointerInputScope.detectDownAndUp(
1310
onDown: (Offset) -> Unit,
1411
onUpOrCancel: (Offset?) -> Unit
1512
) {
1613
forEachGesture {
17-
coroutineScope {
18-
awaitPointerEventScope {
19-
awaitFirstDown(false).also {
20-
onDown(it.position)
21-
}
22-
23-
val up = waitForUpOrCancel()
24-
onUpOrCancel.invoke(up?.position)
14+
awaitPointerEventScope {
15+
awaitFirstDown(false).also {
16+
onDown(it.position)
2517
}
18+
19+
val up = waitForUpOrCancel()
20+
onUpOrCancel(up?.position)
2621
}
2722
}
2823
}
@@ -35,12 +30,12 @@ suspend fun AwaitPointerEventScope.waitForUpOrCancel(): PointerInputChange? {
3530
return event.changes[0]
3631
}
3732

38-
if (event.changes.fastAny { it.isOutOfBounds(size) }) {
33+
if (event.changes.fastAll { it.isOutOfBounds(size) }) {
3934
return null // Canceled
4035
}
4136

4237
val final = awaitPointerEvent(PointerEventPass.Final)
43-
if (final.changes.fastAny { !it.pressed }) {
38+
if (final.changes.fastAll { !it.pressed }) {
4439
return final.changes[0]
4540
}
4641
}

ptr-compose/src/main/java/wtf/s1/ui/nsptr/compose/NSPtrLayout.kt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ sealed class PtrComponent {
3434
class NSPtrState(
3535
val contentInitPosition: Dp = 0.dp,
3636
val contentRefreshPosition: Dp = 54.dp,
37-
@Stable val pullFriction: Float = 0.56f,
37+
val pullFriction: Float = 0.56f,
3838
coroutineScope: CoroutineScope,
3939
onRefresh: (suspend (NSPtrState) -> Unit)? = null,
4040
) {
@@ -63,8 +63,8 @@ class NSPtrState(
6363
animateContentTo(contentInitPositionPx)
6464
}
6565
is SideEffect.OnRefreshing -> {
66-
animateContentTo(contentRefreshPositionPx)
6766
onRefresh?.invoke(this@NSPtrState)
67+
animateContentTo(contentRefreshPositionPx)
6868
}
6969
else -> {
7070

0 commit comments

Comments
 (0)