oleksandrbalan / pagecurl

This library allows to create an effect of turning pages, which can be used in book reader applications, custom on-boarding screens or elsewhere.
Apache License 2.0
345 stars 32 forks source link

control flipping forward or backward #18

Closed choristery closed 1 year ago

choristery commented 1 year ago

"Hi, I've encountered an issue while using this. Since I need to create PageCurlConfig before creating PageCurlState, how can I control flipping forward or backward using PageCurlState in the onCustomTap? I tried using stateOf along with LaunchedEffect to trigger the offset change in onCustomTap, but it causes recomposition. Do you have any suggestions?"

oleksandrbalan commented 1 year ago

Hey 👋

Actually I do not understand why I have merged PageCurlConfig into PageCurlState 🤷

As for (todays) me they could be independent and thus you may create a state before config to perform your custom logic in onCustomTap. I have split them in PR #19, so the new usage would be:

val state = rememberPageCurlState()
val config = rememberPageCurlConfig(
    onCustomTap = { size, position ->
        // You may access `state` here to flip forward / backward
    }
)

PageCurl(
    count = ...,
    state = state,
    config = config,
) { index ->
    ...
}

Will it solve your case?

choristery commented 1 year ago

Sure, that would be a perfect solution. Thank you for your help.

oleksandrbalan commented 1 year ago

Awesome, thanks for confirming.

It should be a part of the 1.4.0 release.