Skip to content

Commit

Permalink
update demos and README.md
Browse files Browse the repository at this point in the history
  • Loading branch information
SmartToolFactory committed Sep 13, 2022
1 parent a12c6f5 commit 2909024
Show file tree
Hide file tree
Showing 3 changed files with 76 additions and 27 deletions.
90 changes: 69 additions & 21 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,39 +7,87 @@ based on how far they are to selector items
https://user-images.githubusercontent.com/35650605/188903459-382f80f1-b77e-427f-9a0d-d50c39dd5406.mp4


## AnimatedCircularList
## AnimatedInfiniteLazyRow/Column

### Declaration

```kotlin
@Composable
fun <T> AnimatedCircularList(
modifier: Modifier = Modifier,
items: List<T>,
initialFistVisibleIndex: Int = Int.MAX_VALUE / 2,
lazyListState: LazyListState = rememberLazyListState(initialFistVisibleIndex),
visibleItemCount: Int = 5,
activeItemSize: Dp,
inactiveItemSize: Dp,
spaceBetweenItems: Dp = 4.dp,
selectorIndex: Int = visibleItemCount / 2,
rangeOfSelection: Int = 1,
activeColor: Color = Color.Cyan,
inactiveColor: Color = Color.Gray,
orientation: Orientation = Orientation.Horizontal,
key: ((index: Int) -> Any)? = null,
contentType: (index: Int) -> Any? = { null },
itemContent: @Composable LazyItemScope.(
animationProgress: AnimationProgress, index: Int, size: Dp
) -> Unit
@Composable
fun <T> AnimatedInfiniteLazyColumn(
modifier: Modifier = Modifier,
items: List<T>,
initialFistVisibleIndex: Int = 0,
visibleItemCount: Int = 5,
inactiveItemPercent: Int = 85,
spaceBetweenItems: Dp = 4.dp,
selectorIndex: Int = -1,
itemScaleRange: Int = 1,
showPartialItem: Boolean = false,
activeColor: Color = Color.Cyan,
inactiveColor: Color = Color.Gray,
key: ((index: Int) -> Any)? = null,
contentType: (index: Int) -> Any? = { null },
itemContent: @Composable LazyItemScope.(
animationProgress: AnimationProgress, index: Int, item: T, height: Dp
) -> Unit
) {
AnimatedInfiniteList(
modifier = modifier,
items = items,
initialFirstVisibleIndex = initialFistVisibleIndex,
visibleItemCount = visibleItemCount,
inactiveItemPercent = inactiveItemPercent,
spaceBetweenItems = spaceBetweenItems,
selectorIndex = selectorIndex,
itemScaleRange = itemScaleRange,
showPartialItem = showPartialItem,
activeColor = activeColor,
inactiveColor = inactiveColor,
orientation = Orientation.Vertical,
key = key,
contentType = contentType,
itemContent = itemContent
)
}
```

```kotlin
@Composable
fun <T> AnimatedInfiniteLazyRow(
modifier: Modifier = Modifier,
items: List<T>,
initialFistVisibleIndex: Int = 0,
activeItemWidth: Dp,
inactiveItemWidth: Dp,
visibleItemCount: Int = 5,
spaceBetweenItems: Dp = 4.dp,
selectorIndex: Int = -1,
itemScaleRange: Int = 1,
showPartialItem: Boolean = false,
activeColor: Color = ActiveColor,
inactiveColor: Color = InactiveColor,
key: ((index: Int) -> Any)? = null,
contentType: (index: Int) -> Any? = { null },
itemContent: @Composable LazyItemScope.(
animationProgress: AnimationProgress, index: Int, item: T, width: Dp
) -> Unit
)
```

### Params

* **items** the data list
* **visibleItemCount** count of items that are visible at any time
* **inactiveItemPercent** percentage of scale that items inside **itemScaleRange**
* can be scaled down to. This is a number between 0 and 100
* **spaceBetweenItems** padding between 2 items
* **selectorIndex** index of selector. When **itemScaleRange** is odd number it's center of selected
item, when **itemScaleRange** is even number it's center of item with selector index and the one
next to it
* **itemScaleRange** range of area of scaling. When this value is odd any item that enters half of
item size range subject to being scaled. When this value is even any item in 2 item size range is
subject to being scaled
* **showPartialItem** show items partially that are at the start and end
* **activeColor** color of selected item
* **inactiveColor** color of items are not selected
* **key** a factory of stable and unique keys representing the item. Using the same key for multiple
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ import com.smarttoolfactory.composeanimatedlist.ShapeSelection
import com.smarttoolfactory.composeanimatedlist.SnackCard
import com.smarttoolfactory.composeanimatedlist.aspectRatios
import com.smarttoolfactory.composeanimatedlist.snacks
import kotlin.math.absoluteValue


@Composable
Expand All @@ -40,11 +39,9 @@ fun AnimatedInfiniteListDemo() {

// Demonstrating for setting first visible item of list if we want to
// make last second item from the end and last item as initial selected item
val initialVisibleItem = -2
val initialVisibleItem = 0
val visibleItemCount = 5
val initialSelectedItem =
(aspectRatios.size-1 + initialVisibleItem + visibleItemCount / 2)
.absoluteValue % aspectRatios.size
val initialSelectedItem = 2

var selectedItem by remember {
mutableStateOf(initialSelectedItem)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package com.smarttoolfactory.composeanimatedlist.demo

import androidx.compose.foundation.background
import androidx.compose.foundation.border
import androidx.compose.foundation.layout.*
import androidx.compose.foundation.shape.CircleShape
import androidx.compose.material3.MaterialTheme
Expand Down Expand Up @@ -143,7 +144,10 @@ fun AnimatedInfiniteListDemo2() {
Spacer(modifier = Modifier.height(30.dp))

AnimatedInfiniteLazyRow(
modifier = Modifier.fillMaxWidth(),
modifier = Modifier
.padding(20.dp)
.fillMaxWidth()
.border(1.dp,Color.Green),
items = aspectRatios,
visibleItemCount = visibleIteCount.toInt(),
selectorIndex = selectorIndex.toInt(),
Expand Down

0 comments on commit 2909024

Please sign in to comment.