Add dynamic max support

This commit is contained in:
Oleksandr Balan
2023-03-21 17:35:16 +01:00
parent 2c1d7b3ef9
commit 27a3ae2e79
14 changed files with 237 additions and 26 deletions

View File

@@ -46,13 +46,12 @@ dependencies {
### Use in Composable
The `PageCurl` has 2 mandatory arguments:
* **state** - The state of the PageCurl. Use it to programmatically change the current page or observe changes, and to configure shadow, back-page and interactions.
* **content** - The content lambda to provide the page composable. Receives the page number.
* **count** - The count of pages.
* **content** - The content lambda to provide the page composable. Receives the page number.
```
val pages = listOf("One", "Two", "Three")
val state = rememberPageCurlState(max = pages.size)
PageCurl(state = state) { index ->
PageCurl(count = pages.size) { index ->
Box(
contentAlignment = Alignment.Center,
modifier = Modifier
@@ -67,6 +66,36 @@ PageCurl(state = state) { index ->
}
```
Optionally `state` could be provided to observe and manage PageCurl state.
* **state** - The state of the PageCurl. Use it to programmatically change the current page or observe changes, and to configure shadow, back-page and interactions.
```
Column {
val scope = rememberCoroutineScope()
val state = rememberPageCurlState()
Button(onClick = { scope.launch { state.next() } }) {
Text(text = "Next")
}
val pages = listOf("One", "Two", "Three")
PageCurl(
count = pages.size,
state = state,
) { index ->
Box(
contentAlignment = Alignment.Center,
modifier = Modifier
.background(MaterialTheme.colors.background)
.fillMaxSize()
) {
Text(
text = pages[index],
style = MaterialTheme.typography.h1,
)
}
}
}
```
See Demo application and [examples](demo/src/main/kotlin/eu/wewox/pagecurl/screens) for more usage examples.
https://user-images.githubusercontent.com/20944869/185782671-2861c2ed-c033-4318-bf12-1d8db74fc8b5.mp4