mirror of
https://github.com/fankes/pagecurl-multiplatform.git
synced 2025-09-04 01:35:36 +08:00
Move PageCurlConfig to PageCurl argument
This commit is contained in:
2
.idea/codeStyles/Project.xml
generated
2
.idea/codeStyles/Project.xml
generated
@@ -45,8 +45,6 @@
|
||||
<package name="kotlinx.android.synthetic" alias="false" withSubpackages="true" />
|
||||
</value>
|
||||
</option>
|
||||
<option name="NAME_COUNT_TO_USE_STAR_IMPORT" value="2147483647" />
|
||||
<option name="NAME_COUNT_TO_USE_STAR_IMPORT_FOR_MEMBERS" value="2147483647" />
|
||||
<option name="WRAP_ELVIS_EXPRESSIONS" value="0" />
|
||||
<option name="CODE_STYLE_DEFAULTS" value="KOTLIN_OFFICIAL" />
|
||||
</JetCodeStyleSettings>
|
||||
|
2
.idea/compiler.xml
generated
2
.idea/compiler.xml
generated
@@ -1,6 +1,6 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project version="4">
|
||||
<component name="CompilerConfiguration">
|
||||
<bytecodeTargetLevel target="11" />
|
||||
<bytecodeTargetLevel target="17" />
|
||||
</component>
|
||||
</project>
|
4
.idea/gradle.xml
generated
4
.idea/gradle.xml
generated
@@ -4,10 +4,9 @@
|
||||
<component name="GradleSettings">
|
||||
<option name="linkedExternalProjectsSettings">
|
||||
<GradleProjectSettings>
|
||||
<option name="testRunner" value="GRADLE" />
|
||||
<option name="distributionType" value="DEFAULT_WRAPPED" />
|
||||
<option name="externalProjectPath" value="$PROJECT_DIR$" />
|
||||
<option name="gradleHome" value="/usr/local/Cellar/gradle/6.0.1/libexec" />
|
||||
<option name="gradleJvm" value="#GRADLE_LOCAL_JAVA_HOME" />
|
||||
<option name="modules">
|
||||
<set>
|
||||
<option value="$PROJECT_DIR$" />
|
||||
@@ -15,6 +14,7 @@
|
||||
<option value="$PROJECT_DIR$/pagecurl" />
|
||||
</set>
|
||||
</option>
|
||||
<option name="resolveExternalAnnotations" value="false" />
|
||||
</GradleProjectSettings>
|
||||
</option>
|
||||
</component>
|
||||
|
10
.idea/migrations.xml
generated
Normal file
10
.idea/migrations.xml
generated
Normal file
@@ -0,0 +1,10 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project version="4">
|
||||
<component name="ProjectMigrations">
|
||||
<option name="MigrateToGradleLocalJavaHome">
|
||||
<set>
|
||||
<option value="$PROJECT_DIR$" />
|
||||
</set>
|
||||
</option>
|
||||
</component>
|
||||
</project>
|
3
.idea/misc.xml
generated
3
.idea/misc.xml
generated
@@ -1,4 +1,3 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project version="4">
|
||||
<component name="DesignSurface">
|
||||
<option name="filePathToZoomLevelMap">
|
||||
@@ -8,7 +7,7 @@
|
||||
</map>
|
||||
</option>
|
||||
</component>
|
||||
<component name="ProjectRootManager" version="2" languageLevel="JDK_11" default="true" project-jdk-name="11" project-jdk-type="JavaSDK">
|
||||
<component name="ProjectRootManager" version="2" languageLevel="JDK_17" default="true" project-jdk-name="jbr-17" project-jdk-type="JavaSDK">
|
||||
<output url="file://$PROJECT_DIR$/build/classes" />
|
||||
</component>
|
||||
<component name="ProjectType">
|
||||
|
@@ -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])
|
||||
}
|
||||
|
@@ -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])
|
||||
}
|
||||
|
@@ -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
|
||||
}
|
||||
|
@@ -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])
|
||||
}
|
||||
|
@@ -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])
|
||||
}
|
||||
|
@@ -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,
|
||||
|
@@ -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,
|
||||
) {
|
||||
|
Reference in New Issue
Block a user