Skip to content

Commit d529f4a

Browse files
committed
change onRefresh callback suspend to normal
1 parent 8557b80 commit d529f4a

File tree

2 files changed

+8
-5
lines changed

2 files changed

+8
-5
lines changed

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ class NSPtrState(
3636
val contentRefreshPosition: Dp = 54.dp,
3737
val pullFriction: Float = 0.56f,
3838
coroutineScope: CoroutineScope,
39-
onRefresh: (suspend (NSPtrState) -> Unit)? = null,
39+
onRefresh: (NSPtrState) -> Unit,
4040
) {
4141

4242
var contentPositionPx: Float by mutableStateOf(0f)
@@ -64,7 +64,7 @@ class NSPtrState(
6464
}
6565
is SideEffect.OnRefreshing -> {
6666
animateContentTo(contentRefreshPositionPx)
67-
onRefresh?.invoke(this@NSPtrState)
67+
onRefresh.invoke(this@NSPtrState)
6868
}
6969
else -> {
7070

@@ -147,7 +147,7 @@ private class NSPtrNestedScrollConnection(val ptrState: NSPtrState) : NestedScro
147147

148148
@Composable
149149
fun NSPtrLayout(
150-
nsPtrState: NSPtrState = NSPtrState(coroutineScope = rememberCoroutineScope()),
150+
nsPtrState: NSPtrState,
151151
modifier: Modifier,
152152
content: @Composable NSPtrScope.() -> Unit
153153
) {

ptr-demo/src/main/java/wtf/s1/android/ptr/demo/InsCompose.kt

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ import androidx.compose.ui.Modifier
1212
import androidx.compose.ui.platform.AbstractComposeView
1313
import androidx.compose.ui.unit.dp
1414
import kotlinx.coroutines.delay
15+
import kotlinx.coroutines.launch
1516
import wtf.s1.ui.nsptr.Event
1617
import wtf.s1.ui.nsptr.compose.NSPtrEZHeader
1718
import wtf.s1.ui.nsptr.compose.NSPtrLayout
@@ -41,8 +42,10 @@ fun Ins() {
4142
contentInitPosition = 0.dp,
4243
contentRefreshPosition = 60.dp
4344
) {
44-
delay(3000)
45-
it.dispatchPtrEvent(Event.RefreshComplete)
45+
coroutine.launch {
46+
delay(3000)
47+
it.dispatchPtrEvent(Event.RefreshComplete)
48+
}
4649
}
4750
}
4851
NSPtrLayout(

0 commit comments

Comments
 (0)