File tree Expand file tree Collapse file tree 2 files changed +10
-15
lines changed
ptr-compose/src/main/java/wtf/s1/ui/nsptr/compose Expand file tree Collapse file tree 2 files changed +10
-15
lines changed Original file line number Diff line number Diff line change @@ -5,24 +5,19 @@ import androidx.compose.foundation.gestures.forEachGesture
55import androidx.compose.ui.geometry.Offset
66import androidx.compose.ui.input.pointer.*
77import androidx.compose.ui.util.fastAll
8- import androidx.compose.ui.util.fastAny
9- import kotlinx.coroutines.coroutineScope
10-
118
129suspend 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 }
Original file line number Diff line number Diff line change @@ -34,7 +34,7 @@ sealed class PtrComponent {
3434class 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
You can’t perform that action at this time.
0 commit comments