diff --git a/build.gradle b/build.gradle index ab3b9c6..92348ce 100644 --- a/build.gradle +++ b/build.gradle @@ -4,7 +4,7 @@ buildscript { min_sdk_version = 24 target_sdk_version = 33 - compose_bom_version = "2023.01.00" + compose_bom_version = "2023.03.00" compose_compiler_version = "1.4.2" accompanist_version = "0.28.0" activity_version = "1.6.1" diff --git a/pagecurl/src/main/kotlin/eu/wewox/pagecurl/page/PageCurl.kt b/pagecurl/src/main/kotlin/eu/wewox/pagecurl/page/PageCurl.kt index 7b4a57a..0c4e2ef 100644 --- a/pagecurl/src/main/kotlin/eu/wewox/pagecurl/page/PageCurl.kt +++ b/pagecurl/src/main/kotlin/eu/wewox/pagecurl/page/PageCurl.kt @@ -4,6 +4,7 @@ import androidx.compose.foundation.layout.Box import androidx.compose.foundation.layout.BoxWithConstraints import androidx.compose.runtime.Composable import androidx.compose.runtime.getValue +import androidx.compose.runtime.key import androidx.compose.runtime.mutableStateOf import androidx.compose.runtime.remember import androidx.compose.runtime.rememberCoroutineScope @@ -69,19 +70,22 @@ public fun PageCurl( onTapBackward = state::prev, ) ) { - if (updatedCurrent + 1 < state.max) { - content(updatedCurrent + 1) - } - - if (updatedCurrent < state.max) { - Box(Modifier.drawCurl(config, internalState.forward.value.top, internalState.forward.value.bottom)) { - content(updatedCurrent) + // Wrap in key to synchronize state updates + key(updatedCurrent, internalState.forward.value, internalState.backward.value) { + if (updatedCurrent + 1 < state.max) { + content(updatedCurrent + 1) } - } - if (updatedCurrent > 0) { - Box(Modifier.drawCurl(config, internalState.backward.value.top, internalState.backward.value.bottom)) { - content(updatedCurrent - 1) + if (updatedCurrent < state.max) { + Box(Modifier.drawCurl(config, internalState.forward.value.top, internalState.forward.value.bottom)) { + content(updatedCurrent) + } + } + + if (updatedCurrent > 0) { + Box(Modifier.drawCurl(config, internalState.backward.value.top, internalState.backward.value.bottom)) { + content(updatedCurrent - 1) + } } } }