Skip to content

Commit

Permalink
update: compose usage mkdocs
Browse files Browse the repository at this point in the history
  • Loading branch information
vipulasri committed Feb 10, 2025
1 parent e752521 commit cda94b7
Show file tree
Hide file tree
Showing 6 changed files with 209 additions and 110 deletions.
Binary file added docs/assets/compose-custom-markers.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified docs/assets/compose-simple-timeline.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added docs/assets/compose-timeline-lazycolumn.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
109 changes: 0 additions & 109 deletions docs/timelineview-compose/overview.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,115 +26,6 @@ dependencies {
}
```

## Basic Usage

### Simple Timeline
```kotlin
Timeline(
modifier = Modifier.height(100.dp),
lineType = LineType.MIDDLE,
lineStyle = LineStyle.dashed(
color = colorResource(R.color.colorAccent),
width = 2.dp
),
marker = {
Box(
modifier = Modifier
.size(24.dp)
.background(
color = colorResource(R.color.colorAccent),
CircleShape
)
)
}
)
```
Output

![Compose Simple Timeline](../assets/compose-simple-timeline.png){ width="100" }

### Timeline with Content

```kotlin
Row(
modifier = Modifier.height(IntrinsicSize.Min)
.padding(start = 16.dp),
verticalAlignment = Alignment.CenterVertically
) {
Timeline(
modifier = Modifier.fillMaxHeight(),
lineType = LineType.MIDDLE,
lineStyle = LineStyle.solid(
color = MaterialTheme.colorScheme.primary,
width = 2.dp
),
marker = {
Icon(
imageVector = Icons.Default.Check,
contentDescription = null,
modifier = Modifier
.size(24.dp)
.background(
color = MaterialTheme.colorScheme.primary,
shape = CircleShape
)
.padding(4.dp),
tint = Color.White
)
}
)

Card(
Modifier.padding(16.dp).weight(1f)
) {
Column(
modifier = Modifier.padding(16.dp)
) {
Text(
text = "Order Placed",
style = MaterialTheme.typography.titleMedium
)
Text(
text = "Your order has been placed",
style = MaterialTheme.typography.bodyMedium
)
}
}
}
```

Output

![Compose Timeline with Content](../assets/compose-timeline-with-content.png){ width="500" }

### Timeline in LazyColumn

```kotlin
LazyColumn {
items(timelineItems.size) { index ->
Row(
modifier = Modifier.padding(16.dp),
verticalAlignment = Alignment.CenterVertically
) {
Timeline(
lineType = getLineType(index, timelineItems.size),
lineStyle = LineStyle.dashed(
color = MaterialTheme.colorScheme.primary,
width = 2.dp,
dashLength = 8.dp,
dashGap = 4.dp
),
marker = {
// Your marker composable
}
)

// Your content composable
}
}
}
```

## Line Types

Timeline supports different line types based on the item's position:
Expand Down
206 changes: 206 additions & 0 deletions docs/timelineview-compose/usage.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,206 @@
# Timeline usage in Compose

### Simple
```kotlin
Timeline(
modifier = Modifier.height(100.dp),
lineType = LineType.MIDDLE,
lineStyle = LineStyle.dashed(
color = MaterialTheme.colorScheme.primary,
width = 2.dp
),
marker = {
Box(
modifier = Modifier
.size(24.dp)
.background(
color = MaterialTheme.colorScheme.primary,
CircleShape
)
)
}
)
```
Output

![Compose Simple Timeline](../assets/compose-simple-timeline.png){ width="100" }

### With Content

```kotlin
Row(
modifier = Modifier.height(IntrinsicSize.Min)
.padding(start = 16.dp),
verticalAlignment = Alignment.CenterVertically
) {
Timeline(
modifier = Modifier.fillMaxHeight(),
lineType = LineType.MIDDLE,
lineStyle = LineStyle.solid(
color = MaterialTheme.colorScheme.primary,
width = 2.dp
),
marker = {
Icon(
imageVector = Icons.Default.Check,
contentDescription = null,
modifier = Modifier
.size(24.dp)
.background(
color = MaterialTheme.colorScheme.primary,
shape = CircleShape
)
.padding(4.dp),
tint = Color.White
)
}
)

Card(
Modifier.padding(16.dp).weight(1f)
) {
Column(
modifier = Modifier.padding(16.dp)
) {
Text(
text = "Order Placed",
style = MaterialTheme.typography.titleMedium
)
Text(
text = "Your order has been placed",
style = MaterialTheme.typography.bodyMedium
)
}
}
}
```

Output

![Compose Timeline with Content](../assets/compose-timeline-with-content.png){ width="500" }

### LazyColumn

```kotlin
LazyColumn {
items(timelineItems.size) { index ->
Row(
modifier = Modifier.padding(16.dp),
verticalAlignment = Alignment.CenterVertically
) {
Timeline(
lineType = getLineType(index, timelineItems.size),
lineStyle = LineStyle.dashed(
color = MaterialTheme.colorScheme.primary,
width = 2.dp,
dashLength = 8.dp,
dashGap = 4.dp
),
marker = {
// Your marker composable
}
)

// Your content composable
}
}
}
```

Output

![Compose Timeline with Content](../assets/compose-timeline-lazycolumn.png){ width="500" }

### Custom Markers with Inconsistent Size

```kotlin
Column(Modifier.padding(horizontal = 16.dp)) {
val totalItems = 4
repeat(totalItems) { position ->

var modifier = Modifier
.height(100.dp)

if (position != 1) {
modifier = modifier.then(Modifier.padding(horizontal = 13.dp))
}

Timeline(
modifier = modifier,
lineType = getLineType(position, totalItems),
lineStyle = when (position) {
0 -> {
LineStyle.dashed(
color = Color.Gray,
width = 3.dp
)
}

1 -> {
LineStyle(
startLine = DashedLine(
color = Color.Gray,
width = 3.dp
),
endLine = SolidLine(
color = MaterialTheme.colorScheme.primary,
width = 3.dp
),
)
}

else -> {
LineStyle.solid(
color = MaterialTheme.colorScheme.primary,
width = 3.dp
)
}
}
) {
// Custom marker examples
when (position) {
0 -> Icon(
imageVector = Icons.Default.Star,
contentDescription = null,
tint = MaterialTheme.colorScheme.primary,
modifier = Modifier.size(24.dp)
)

1 -> Box(
modifier = Modifier
.size(50.dp)
.background(
MaterialTheme.colorScheme.primary,
RoundedCornerShape(4.dp)
)
)

2 -> Box(
Modifier
.size(24.dp)
.background(MaterialTheme.colorScheme.primary, CircleShape)
) {
Text(
modifier = Modifier.align(Alignment.Center),
text = "3",
color = Color.White,
textAlign = TextAlign.Center
)
}

else -> {
Box(
modifier = Modifier
.size(24.dp)
.background(MaterialTheme.colorScheme.primary, CircleShape)
)
}
}
}
}
}
```

Output

![Compose Timeline with Content](../assets/compose-custom-markers.png){ width="100" }
4 changes: 3 additions & 1 deletion mkdocs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,9 @@ nav:
- Android Views:
- Getting Started: timelineview/overview.md
- RecyclerView: timelineview/recyclerview.md
- Compose: timelineview-compose/overview.md
- Compose:
- Getting Started: timelineview-compose/overview.md
- Usage: timelineview-compose/usage.md

extra:
analytics:
Expand Down

0 comments on commit cda94b7

Please sign in to comment.