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 3ee0ad5..2c44cf3 100644 --- a/pagecurl/src/main/kotlin/eu/wewox/pagecurl/page/PageCurl.kt +++ b/pagecurl/src/main/kotlin/eu/wewox/pagecurl/page/PageCurl.kt @@ -26,12 +26,11 @@ public fun PageCurl( content: @Composable (Int) -> Unit ) { val scope = rememberCoroutineScope() - val updatedCurrent by rememberUpdatedState(state.current) BoxWithConstraints(modifier) { - state.max = count - state.setup(constraints) + state.setup(count, constraints) + val updatedCurrent by rememberUpdatedState(state.current) val internalState by rememberUpdatedState(state.internalState ?: return@BoxWithConstraints) val config by rememberUpdatedState(state.config) diff --git a/pagecurl/src/main/kotlin/eu/wewox/pagecurl/page/PageCurlState.kt b/pagecurl/src/main/kotlin/eu/wewox/pagecurl/page/PageCurlState.kt index 0e8d0a0..4d52914 100644 --- a/pagecurl/src/main/kotlin/eu/wewox/pagecurl/page/PageCurlState.kt +++ b/pagecurl/src/main/kotlin/eu/wewox/pagecurl/page/PageCurlState.kt @@ -117,10 +117,17 @@ public class PageCurlState( public val progress: Float get() = internalState?.progress ?: 0f internal var max: Int = initialMax + private set internal var internalState: InternalState? by mutableStateOf(null) + private set + + internal fun setup(count: Int, constraints: Constraints) { + max = count + if (current >= count) { + current = count - 1 + } - internal fun setup(constraints: Constraints) { if (internalState?.constraints == constraints) { return }