diff --git a/.idea/codeStyles/Project.xml b/.idea/codeStyles/Project.xml
index 04f7afe..1b4dd5a 100644
--- a/.idea/codeStyles/Project.xml
+++ b/.idea/codeStyles/Project.xml
@@ -45,8 +45,6 @@
-
-
diff --git a/.idea/compiler.xml b/.idea/compiler.xml
index fb7f4a8..b589d56 100644
--- a/.idea/compiler.xml
+++ b/.idea/compiler.xml
@@ -1,6 +1,6 @@
-
+
\ No newline at end of file
diff --git a/.idea/gradle.xml b/.idea/gradle.xml
index a6b0906..ecb9cfc 100644
--- a/.idea/gradle.xml
+++ b/.idea/gradle.xml
@@ -4,10 +4,9 @@
diff --git a/.idea/migrations.xml b/.idea/migrations.xml
new file mode 100644
index 0000000..f8051a6
--- /dev/null
+++ b/.idea/migrations.xml
@@ -0,0 +1,10 @@
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/.idea/misc.xml b/.idea/misc.xml
index cab9531..c9a2cd7 100644
--- a/.idea/misc.xml
+++ b/.idea/misc.xml
@@ -1,4 +1,3 @@
-
@@ -8,7 +7,7 @@
-
+
diff --git a/demo/src/main/kotlin/eu/wewox/pagecurl/screens/BackPagePageCurlScreen.kt b/demo/src/main/kotlin/eu/wewox/pagecurl/screens/BackPagePageCurlScreen.kt
index 6165a40..c560345 100644
--- a/demo/src/main/kotlin/eu/wewox/pagecurl/screens/BackPagePageCurlScreen.kt
+++ b/demo/src/main/kotlin/eu/wewox/pagecurl/screens/BackPagePageCurlScreen.kt
@@ -52,32 +52,32 @@ fun BackPagePageCurlScreen() {
Box(Modifier.fillMaxSize()) {
val pages = remember { HowToPageData.backPageHowToPages }
var zoomOut by remember { mutableStateOf(false) }
- val state = rememberPageCurlState(
- config = rememberPageCurlConfig(
- onCustomTap = { size, position ->
- // When PageCurl is zoomed out then zoom back in
- // Else detect tap somewhere in the center with 64 radius and zoom out a PageCurl
- if (zoomOut) {
- zoomOut = false
- true
- } else if ((position - size.center.toOffset()).getDistance() < 64.dp.toPx()) {
- zoomOut = true
- true
- } else {
- false
- }
+ val state = rememberPageCurlState()
+ val config = rememberPageCurlConfig(
+ onCustomTap = { size, position ->
+ // When PageCurl is zoomed out then zoom back in
+ // Else detect tap somewhere in the center with 64 radius and zoom out a PageCurl
+ if (zoomOut) {
+ zoomOut = false
+ true
+ } else if ((position - size.center.toOffset()).getDistance() < 64.dp.toPx()) {
+ zoomOut = true
+ true
+ } else {
+ false
}
- )
+ }
)
ZoomOutLayout(
zoomOut = zoomOut,
- config = state.config,
- bottom = { SettingsRow(state.config) },
+ config = config,
+ bottom = { SettingsRow(config) },
) {
PageCurl(
count = pages.size,
state = state,
+ config = config,
) { index ->
HowToPage(index, pages[index])
}
diff --git a/demo/src/main/kotlin/eu/wewox/pagecurl/screens/InteractionConfigInPageCurl.kt b/demo/src/main/kotlin/eu/wewox/pagecurl/screens/InteractionConfigInPageCurl.kt
index d440db8..cf6fe24 100644
--- a/demo/src/main/kotlin/eu/wewox/pagecurl/screens/InteractionConfigInPageCurl.kt
+++ b/demo/src/main/kotlin/eu/wewox/pagecurl/screens/InteractionConfigInPageCurl.kt
@@ -47,32 +47,32 @@ fun InteractionConfigInPageCurlScreen() {
Box(Modifier.fillMaxSize()) {
val pages = remember { HowToPageData.interactionSettingsHowToPages }
var zoomOut by remember { mutableStateOf(false) }
- val state = rememberPageCurlState(
- config = rememberPageCurlConfig(
- onCustomTap = { size, position ->
- // When PageCurl is zoomed out then zoom back in
- // Else detect tap somewhere in the center with 64 radius and zoom out a PageCurl
- if (zoomOut) {
- zoomOut = false
- true
- } else if ((position - size.center.toOffset()).getDistance() < 64.dp.toPx()) {
- zoomOut = true
- true
- } else {
- false
- }
+ val state = rememberPageCurlState()
+ val config = rememberPageCurlConfig(
+ onCustomTap = { size, position ->
+ // When PageCurl is zoomed out then zoom back in
+ // Else detect tap somewhere in the center with 64 radius and zoom out a PageCurl
+ if (zoomOut) {
+ zoomOut = false
+ true
+ } else if ((position - size.center.toOffset()).getDistance() < 64.dp.toPx()) {
+ zoomOut = true
+ true
+ } else {
+ false
}
- )
+ }
)
ZoomOutLayout(
zoomOut = zoomOut,
- config = state.config,
- bottom = { SettingsRow(state.config) },
+ config = config,
+ bottom = { SettingsRow(config) },
) {
PageCurl(
count = pages.size,
state = state,
+ config = config,
) { index ->
HowToPage(index, pages[index])
}
diff --git a/demo/src/main/kotlin/eu/wewox/pagecurl/screens/SettingsPageCurlScreen.kt b/demo/src/main/kotlin/eu/wewox/pagecurl/screens/SettingsPageCurlScreen.kt
index b60b0fa..fa1d6a3 100644
--- a/demo/src/main/kotlin/eu/wewox/pagecurl/screens/SettingsPageCurlScreen.kt
+++ b/demo/src/main/kotlin/eu/wewox/pagecurl/screens/SettingsPageCurlScreen.kt
@@ -33,30 +33,30 @@ fun SettingsPageCurlScreen() {
var showPopup by rememberSaveable { mutableStateOf(false) }
- val state = rememberPageCurlState(
- config = rememberPageCurlConfig(
- onCustomTap = { size, position ->
- // Detect tap somewhere in the center with 64 radius and show popup
- if ((position - size.center.toOffset()).getDistance() < 64.dp.toPx()) {
- showPopup = true
- true
- } else {
- false
- }
+ val state = rememberPageCurlState()
+ val config = rememberPageCurlConfig(
+ onCustomTap = { size, position ->
+ // Detect tap somewhere in the center with 64 radius and show popup
+ if ((position - size.center.toOffset()).getDistance() < 64.dp.toPx()) {
+ showPopup = true
+ true
+ } else {
+ false
}
- )
+ }
)
PageCurl(
count = pages.size,
state = state,
+ config = config,
) { index ->
HowToPage(index, pages[index])
}
if (showPopup) {
SettingsPopup(
- config = state.config,
+ config = config,
onDismiss = {
showPopup = false
}
diff --git a/demo/src/main/kotlin/eu/wewox/pagecurl/screens/ShadowInPageCurlScreen.kt b/demo/src/main/kotlin/eu/wewox/pagecurl/screens/ShadowInPageCurlScreen.kt
index 0df03ac..8bab813 100644
--- a/demo/src/main/kotlin/eu/wewox/pagecurl/screens/ShadowInPageCurlScreen.kt
+++ b/demo/src/main/kotlin/eu/wewox/pagecurl/screens/ShadowInPageCurlScreen.kt
@@ -39,32 +39,32 @@ fun ShadowInPageCurlScreen() {
Box(Modifier.fillMaxSize()) {
val pages = remember { HowToPageData.shadowHowToPages }
var zoomOut by remember { mutableStateOf(false) }
- val state = rememberPageCurlState(
- config = rememberPageCurlConfig(
- onCustomTap = { size, position ->
- // When PageCurl is zoomed out then zoom back in
- // Else detect tap somewhere in the center with 64 radius and zoom out a PageCurl
- if (zoomOut) {
- zoomOut = false
- true
- } else if ((position - size.center.toOffset()).getDistance() < 64.dp.toPx()) {
- zoomOut = true
- true
- } else {
- false
- }
+ val state = rememberPageCurlState()
+ val config = rememberPageCurlConfig(
+ onCustomTap = { size, position ->
+ // When PageCurl is zoomed out then zoom back in
+ // Else detect tap somewhere in the center with 64 radius and zoom out a PageCurl
+ if (zoomOut) {
+ zoomOut = false
+ true
+ } else if ((position - size.center.toOffset()).getDistance() < 64.dp.toPx()) {
+ zoomOut = true
+ true
+ } else {
+ false
}
- )
+ }
)
ZoomOutLayout(
zoomOut = zoomOut,
- config = state.config,
- bottom = { SettingsRow(state.config) },
+ config = config,
+ bottom = { SettingsRow(config) },
) {
PageCurl(
count = pages.size,
state = state,
+ config = config,
) { index ->
HowToPage(index, pages[index])
}
diff --git a/demo/src/main/kotlin/eu/wewox/pagecurl/screens/StateInPageCurlScreen.kt b/demo/src/main/kotlin/eu/wewox/pagecurl/screens/StateInPageCurlScreen.kt
index 6196fa6..5082380 100644
--- a/demo/src/main/kotlin/eu/wewox/pagecurl/screens/StateInPageCurlScreen.kt
+++ b/demo/src/main/kotlin/eu/wewox/pagecurl/screens/StateInPageCurlScreen.kt
@@ -44,32 +44,32 @@ fun StateInPageCurlScreen() {
Box(Modifier.fillMaxSize()) {
val pages = remember { HowToPageData.stateHowToPages }
var zoomOut by remember { mutableStateOf(false) }
- val state = rememberPageCurlState(
- config = rememberPageCurlConfig(
- onCustomTap = { size, position ->
- // When PageCurl is zoomed out then zoom back in
- // Else detect tap somewhere in the center with 64 radius and zoom out a PageCurl
- if (zoomOut) {
- zoomOut = false
- true
- } else if ((position - size.center.toOffset()).getDistance() < 64.dp.toPx()) {
- zoomOut = true
- true
- } else {
- false
- }
+ val state = rememberPageCurlState()
+ val config = rememberPageCurlConfig(
+ onCustomTap = { size, position ->
+ // When PageCurl is zoomed out then zoom back in
+ // Else detect tap somewhere in the center with 64 radius and zoom out a PageCurl
+ if (zoomOut) {
+ zoomOut = false
+ true
+ } else if ((position - size.center.toOffset()).getDistance() < 64.dp.toPx()) {
+ zoomOut = true
+ true
+ } else {
+ false
}
- )
+ }
)
ZoomOutLayout(
zoomOut = zoomOut,
- config = state.config,
+ config = config,
bottom = { SettingsRow(pages.size, state) },
) {
PageCurl(
count = pages.size,
state = state,
+ config = config,
) { index ->
HowToPage(index, pages[index])
}
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 09d63f5..4c3d667 100644
--- a/pagecurl/src/main/kotlin/eu/wewox/pagecurl/page/PageCurl.kt
+++ b/pagecurl/src/main/kotlin/eu/wewox/pagecurl/page/PageCurl.kt
@@ -12,13 +12,16 @@ import androidx.compose.runtime.rememberUpdatedState
import androidx.compose.runtime.setValue
import androidx.compose.ui.Modifier
import eu.wewox.pagecurl.ExperimentalPageCurlApi
+import eu.wewox.pagecurl.config.PageCurlConfig
+import eu.wewox.pagecurl.config.rememberPageCurlConfig
/**
* Shows the pages which may be turned by drag or tap gestures.
*
* @param count The count of pages.
- * @param state The state of the PageCurl. Use this to programmatically change the current page or observe changes.
* @param modifier The modifier for this composable.
+ * @param state The state of the PageCurl. Use this to programmatically change the current page or observe changes.
+ * @param config The configuration for PageCurl.
* @param content The content lambda to provide the page composable. Receives the page number.
*/
@ExperimentalPageCurlApi
@@ -27,6 +30,7 @@ public fun PageCurl(
count: Int,
modifier: Modifier = Modifier,
state: PageCurlState = rememberPageCurlState(),
+ config: PageCurlConfig = rememberPageCurlConfig(),
content: @Composable (Int) -> Unit
) {
val scope = rememberCoroutineScope()
@@ -37,13 +41,13 @@ public fun PageCurl(
val updatedCurrent by rememberUpdatedState(state.current)
val internalState by rememberUpdatedState(state.internalState ?: return@BoxWithConstraints)
- val config by rememberUpdatedState(state.config)
+ val config by rememberUpdatedState(config)
Box(
Modifier
.curlGesture(
state = internalState,
- enabled = state.config.dragForwardEnabled && updatedCurrent < state.max - 1,
+ enabled = config.dragForwardEnabled && updatedCurrent < state.max - 1,
scope = scope,
targetStart = config.dragForwardInteraction.start,
targetEnd = config.dragForwardInteraction.end,
@@ -54,7 +58,7 @@ public fun PageCurl(
)
.curlGesture(
state = internalState,
- enabled = state.config.dragBackwardEnabled && updatedCurrent > 0,
+ enabled = config.dragBackwardEnabled && updatedCurrent > 0,
scope = scope,
targetStart = config.dragBackwardInteraction.start,
targetEnd = config.dragBackwardInteraction.end,
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 54d8fd7..b5d20d3 100644
--- a/pagecurl/src/main/kotlin/eu/wewox/pagecurl/page/PageCurlState.kt
+++ b/pagecurl/src/main/kotlin/eu/wewox/pagecurl/page/PageCurlState.kt
@@ -28,30 +28,52 @@ import kotlinx.coroutines.withContext
* Remembers the [PageCurlState].
*
* @param initialCurrent The initial current page.
- * @param config The configuration for PageCurl.
* @return The remembered [PageCurlState].
*/
@ExperimentalPageCurlApi
@Composable
public fun rememberPageCurlState(
initialCurrent: Int = 0,
- config: PageCurlConfig = rememberPageCurlConfig()
): PageCurlState =
rememberSaveable(
initialCurrent,
saver = Saver(
save = { it.current },
- restore = {
- PageCurlState(
- initialCurrent = it,
- config = config,
- )
- }
+ restore = { PageCurlState(initialCurrent = it) }
+ )
+ ) {
+ PageCurlState(
+ initialCurrent = initialCurrent,
+ )
+ }
+
+/**
+ * Remembers the [PageCurlState].
+ *
+ * @param initialCurrent The initial current page.
+ * @param config The configuration for PageCurl.
+ * @return The remembered [PageCurlState].
+ */
+@ExperimentalPageCurlApi
+@Composable
+@Deprecated(
+ message = "Specify 'config' as 'config' in PageCurl composable.",
+ level = DeprecationLevel.ERROR,
+)
+@Suppress("UnusedPrivateMember")
+public fun rememberPageCurlState(
+ initialCurrent: Int = 0,
+ config: PageCurlConfig,
+): PageCurlState =
+ rememberSaveable(
+ initialCurrent,
+ saver = Saver(
+ save = { it.current },
+ restore = { PageCurlState(initialCurrent = it) }
)
) {
PageCurlState(
initialCurrent = initialCurrent,
- config = config,
)
}
@@ -65,7 +87,11 @@ public fun rememberPageCurlState(
*/
@ExperimentalPageCurlApi
@Composable
-@Deprecated("Specify 'max' as 'count' in PageCurl composable.")
+@Deprecated(
+ message = "Specify 'max' as 'count' in PageCurl composable and 'config' as 'config' in PageCurl composable.",
+ level = DeprecationLevel.ERROR,
+)
+@Suppress("UnusedPrivateMember")
public fun rememberPageCurlState(
max: Int,
initialCurrent: Int = 0,
@@ -79,7 +105,6 @@ public fun rememberPageCurlState(
PageCurlState(
initialCurrent = it,
initialMax = max,
- config = config,
)
}
)
@@ -87,20 +112,17 @@ public fun rememberPageCurlState(
PageCurlState(
initialCurrent = initialCurrent,
initialMax = max,
- config = config,
)
}
/**
* The state of the PageCurl.
*
- * @property config The configuration for PageCurl.
* @param initialMax The initial max number of pages.
* @param initialCurrent The initial current page.
*/
@ExperimentalPageCurlApi
public class PageCurlState(
- public val config: PageCurlConfig,
initialMax: Int = 0,
initialCurrent: Int = 0,
) {