From e19b42e98cc9c412d1a84b3bf945c250f514276a Mon Sep 17 00:00:00 2001 From: Arkadii Ivanov Date: Wed, 27 Sep 2023 21:29:01 +0100 Subject: [PATCH] Fixed Pages not calling onPageSelected when swiping fast --- .../decompose/extensions/compose/jetbrains/pages/Pages.kt | 4 ++-- .../extensions/compose/jetbrains/pages/PagesTest.kt | 5 +++-- .../decompose/extensions/compose/jetpack/pages/PagesTest.kt | 5 +++-- .../decompose/extensions/compose/jetpack/pages/Pages.kt | 4 ++-- 4 files changed, 10 insertions(+), 8 deletions(-) diff --git a/extensions-compose-jetbrains/src/commonMain/kotlin/com/arkivanov/decompose/extensions/compose/jetbrains/pages/Pages.kt b/extensions-compose-jetbrains/src/commonMain/kotlin/com/arkivanov/decompose/extensions/compose/jetbrains/pages/Pages.kt index bdbebed22..a673299a4 100644 --- a/extensions-compose-jetbrains/src/commonMain/kotlin/com/arkivanov/decompose/extensions/compose/jetbrains/pages/Pages.kt +++ b/extensions-compose-jetbrains/src/commonMain/kotlin/com/arkivanov/decompose/extensions/compose/jetbrains/pages/Pages.kt @@ -74,8 +74,8 @@ fun Pages( } } - DisposableEffect(state.settledPage) { - onPageSelected(state.settledPage) + DisposableEffect(state.currentPage) { + onPageSelected(state.currentPage) onDispose {} } diff --git a/extensions-compose-jetbrains/src/jvmTest/kotlin/com/arkivanov/decompose/extensions/compose/jetbrains/pages/PagesTest.kt b/extensions-compose-jetbrains/src/jvmTest/kotlin/com/arkivanov/decompose/extensions/compose/jetbrains/pages/PagesTest.kt index ee00ab572..135eebdca 100644 --- a/extensions-compose-jetbrains/src/jvmTest/kotlin/com/arkivanov/decompose/extensions/compose/jetbrains/pages/PagesTest.kt +++ b/extensions-compose-jetbrains/src/jvmTest/kotlin/com/arkivanov/decompose/extensions/compose/jetbrains/pages/PagesTest.kt @@ -16,6 +16,7 @@ import kotlinx.coroutines.runBlocking import org.junit.Rule import kotlin.test.Test +@Suppress("TestFunctionName") class PagesTest { @get:Rule @@ -23,7 +24,7 @@ class PagesTest { @OptIn(ExperimentalDecomposeApi::class) @Test - fun GIVEN_pages_dislpayed_WHEN_page_state_changed_THEN_pageCount_updated() { + fun GIVEN_pages_displayed_WHEN_page_state_changed_THEN_pageCount_updated() { runBlocking(Dispatchers.Main) { val state = mutableStateOf( ChildPages( @@ -55,7 +56,7 @@ class PagesTest { @OptIn(ExperimentalDecomposeApi::class) @Test - fun GIVEN_page0_dislpayed_WHEN_switching_pages_THEN_current_page_updated() { + fun GIVEN_page0_displayed_WHEN_switching_pages_THEN_current_page_updated() { runBlocking(Dispatchers.Main) { val state = mutableStateOf( ChildPages( diff --git a/extensions-compose-jetpack/src/androidTest/java/com/arkivanov/decompose/extensions/compose/jetpack/pages/PagesTest.kt b/extensions-compose-jetpack/src/androidTest/java/com/arkivanov/decompose/extensions/compose/jetpack/pages/PagesTest.kt index 849482e41..17d3b9e60 100644 --- a/extensions-compose-jetpack/src/androidTest/java/com/arkivanov/decompose/extensions/compose/jetpack/pages/PagesTest.kt +++ b/extensions-compose-jetpack/src/androidTest/java/com/arkivanov/decompose/extensions/compose/jetpack/pages/PagesTest.kt @@ -15,6 +15,7 @@ import org.junit.Rule import org.junit.Test import java.io.Serializable +@Suppress("TestFunctionName") class PagesTest { @get:Rule @@ -22,7 +23,7 @@ class PagesTest { @OptIn(ExperimentalDecomposeApi::class) @Test - fun GIVEN_pages_dislpayed_WHEN_page_state_changed_THEN_pageCount_updated() { + fun GIVEN_pages_displayed_WHEN_page_state_changed_THEN_pageCount_updated() { val state = mutableStateOf( ChildPages( items = listOf( @@ -52,7 +53,7 @@ class PagesTest { @OptIn(ExperimentalDecomposeApi::class) @Test - fun GIVEN_page0_dislpayed_WHEN_switching_pages_THEN_current_page_updated() { + fun GIVEN_page0_displayed_WHEN_switching_pages_THEN_current_page_updated() { val state = mutableStateOf( ChildPages( items = listOf( diff --git a/extensions-compose-jetpack/src/main/java/com/arkivanov/decompose/extensions/compose/jetpack/pages/Pages.kt b/extensions-compose-jetpack/src/main/java/com/arkivanov/decompose/extensions/compose/jetpack/pages/Pages.kt index 522794e09..9698fbd0f 100644 --- a/extensions-compose-jetpack/src/main/java/com/arkivanov/decompose/extensions/compose/jetpack/pages/Pages.kt +++ b/extensions-compose-jetpack/src/main/java/com/arkivanov/decompose/extensions/compose/jetpack/pages/Pages.kt @@ -74,8 +74,8 @@ fun Pages( } } - DisposableEffect(state.settledPage) { - onPageSelected(state.settledPage) + DisposableEffect(state.currentPage) { + onPageSelected(state.currentPage) onDispose {} }