Skip to content

Commit

Permalink
Use rememberUpdatedState for refresh actions
Browse files Browse the repository at this point in the history
  • Loading branch information
aabewhite committed Jul 23, 2024
1 parent 89dfd66 commit cb5d796
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 2 deletions.
3 changes: 2 additions & 1 deletion Sources/SkipUI/SkipUI/Containers/List.swift
Original file line number Diff line number Diff line change
Expand Up @@ -115,10 +115,11 @@ public final class List : View {
let refreshState: PullRefreshState?
if let refreshAction {
let refreshScope = rememberCoroutineScope()
let updatedAction = rememberUpdatedState(refreshAction)
refreshState = rememberPullRefreshState(refreshing.value, {
refreshScope.launch {
refreshing.value = true
refreshAction()
updatedAction.value()
refreshing.value = false
}
})
Expand Down
4 changes: 3 additions & 1 deletion Sources/SkipUI/SkipUI/Containers/ScrollView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import androidx.compose.runtime.Composable
import androidx.compose.runtime.mutableStateOf
import androidx.compose.runtime.remember
import androidx.compose.runtime.rememberCoroutineScope
import androidx.compose.runtime.rememberUpdatedState
import androidx.compose.ui.Modifier
import kotlinx.coroutines.launch
#else
Expand Down Expand Up @@ -65,10 +66,11 @@ public struct ScrollView : View {
let refreshAction = EnvironmentValues.shared.refresh
let refreshState: PullRefreshState?
if let refreshAction {
let updatedAction = rememberUpdatedState(refreshAction)
refreshState = rememberPullRefreshState(refreshing.value, {
coroutineScope.launch {
refreshing.value = true
refreshAction()
updatedAction.value()
refreshing.value = false
}
})
Expand Down

0 comments on commit cb5d796

Please sign in to comment.