RepeatWithIndex
DSL function to repeat content N times with index access
RepeatWithIndex
Module: jindong-compose | Package: io.github.compose.jindong.dsl
Repeats the content block N times, providing the iteration index to each repetition.
Signature
Parameters
| Parameter | Type | Description |
|---|---|---|
count | Int | Number of times to repeat (must be non-negative) |
content | @Composable JindongScope.(index: Int) -> Unit | Pattern with 0-based index |
Description
RepeatWithIndex is similar to Repeat but provides the current iteration index (0-based) to the content block. This enables dynamic patterns where each iteration can have different parameters.
Unlike Repeat which creates a single RepeatNode, RepeatWithIndex generates N different child nodes at composition time, allowing each iteration to be unique.
Usage
Basic Usage
Dynamic Intensity
Dynamic Duration
Examples
Fade Out Effect
Fade In Effect
Accelerating Pattern
Wave Pattern
Crescendo
vs Repeat
| Feature | Repeat | RepeatWithIndex |
|---|---|---|
| Index access | No | Yes |
| Dynamic content | No | Yes |
| Implementation | Single RepeatNode | N separate nodes |
| Use case | Identical iterations | Varying iterations |
Choose Repeat for simple repetition:
Choose RepeatWithIndex for dynamic patterns:
Notes
- Index is 0-based (0 to count-1)
- Each iteration generates a separate node
countmust be a positive value.- The index can be used in any expression within the content block