|
1 | 1 | # StickyTimeLine
|
2 | 2 |
|
| 3 | +[](https://search.maven.org/artifact/io.github.sangcomz/stickytimeline-compose) |
3 | 4 | [](https://search.maven.org/artifact/io.github.sangcomz/StickyTimeLine)
|
4 | 5 |
|
5 |
| -StickyTimeLine is timeline view for android. |
| 6 | +StickyTimeLine is timeline view for android. Now supports both View system and Jetpack Compose! |
6 | 7 |
|
7 | 8 | ## What's New? :tada:
|
8 |
| -- [Improvement] lib version update |
| 9 | +- [New] Jetpack Compose version released! 🎉 |
9 | 10 |
|
10 | 11 | ## Result Screen
|
11 | 12 |
|
12 | 13 | Feel free to send me a pull request with your app and I'll link you here:
|
13 |
| - |
| 14 | + ### Jetpack Compose |
| 15 | +| Sample | |
| 16 | + |:----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------:| |
| 17 | +| <img width="auto" height="500px" src="/pic/compose.gif"> | |
| 18 | + |
| 19 | +### View System |
14 | 20 | | Sample <p style="float:left;"> <a href="https://play.google.com/store/apps/details?id=xyz.sangcomz.stickytimeline"> <img HEIGHT="40" WIDTH="135" alt="Get it on Google Play" src="https://play.google.com/intl/en_us/badges/images/apps/en-play-badge.png" /></a></p> | AlleysMap <p style="float:left;"> <a href="https://play.google.com/store/apps/details?id=co.alleys.android"> <img HEIGHT="40" WIDTH="135" alt="Get it on Google Play" src="https://play.google.com/intl/en_us/badges/images/apps/en-play-badge.png" /> </a></p> | StockRoom <p style="float:left;"> <a href="https://play.google.com/store/apps/details?id=com.thecloudsite.stockroom"> <img HEIGHT="40" WIDTH="135" alt="Get it on Google Play" src="https://play.google.com/intl/en_us/badges/images/apps/en-play-badge.png" /></a></p> |
|
15 | 21 | |:---------------------------------:|:--------------------------------:|:--------------------------------:|
|
16 | 22 | | <img src="/pic/sample_result.gif">|<img src="/pic/alleys_result.gif">|<img width="auto" height="500px" src="/pic/stockroom_result.gif">|
|
17 | 23 |
|
18 | 24 | ## How to Use
|
19 | 25 |
|
20 | 26 | ### Gradle
|
21 |
| -[](https://search.maven.org/artifact/io.github.sangcomz/StickyTimeLine) |
| 27 | + |
| 28 | +#### View System |
22 | 29 | ```groovy
|
23 | 30 | dependencies {
|
24 | 31 | implementation 'io.github.sangcomz:StickyTimeLine:x.x.x'
|
25 | 32 | }
|
26 | 33 | ```
|
| 34 | + |
| 35 | +#### Jetpack Compose |
| 36 | +```groovy |
| 37 | + dependencies { |
| 38 | + implementation 'io.github.sangcomz:stickytimeline-compose:x.x.x' |
| 39 | + } |
| 40 | +``` |
27 | 41 | ### Usage
|
28 |
| -#### activity_main.xml |
| 42 | + |
| 43 | +#### Jetpack Compose Usage |
| 44 | + |
| 45 | +##### Basic Usage - LazyColumn |
| 46 | +```kotlin |
| 47 | +@Composable |
| 48 | +fun TimeLineExample() { |
| 49 | + val musicList = remember { MusicRepo().musicList } |
| 50 | + val sortedMusicList = musicList.sortedWith( |
| 51 | + compareBy( |
| 52 | + { it.year.toIntOrNull() ?: 0 }, |
| 53 | + { it.month.toIntOrNull() ?: 0 } |
| 54 | + ) |
| 55 | + ) |
| 56 | + |
| 57 | + StickyTimeLineLazyColumn( |
| 58 | + items = sortedMusicList, |
| 59 | + groupBy = { it.year }, |
| 60 | + makeHeaderItem = { key, _ -> key }, |
| 61 | + sectionHeader = { year -> |
| 62 | + Column( |
| 63 | + modifier = Modifier |
| 64 | + .background(Color.White) |
| 65 | + .padding(8.dp) |
| 66 | + .fillMaxWidth() |
| 67 | + ) { |
| 68 | + Text( |
| 69 | + text = year, |
| 70 | + style = TextStyle( |
| 71 | + fontSize = 18.sp, |
| 72 | + fontWeight = FontWeight.Bold, |
| 73 | + color = Color(0xFF414FCA) |
| 74 | + ) |
| 75 | + ) |
| 76 | + Text( |
| 77 | + text = "Popular Music", |
| 78 | + style = TextStyle( |
| 79 | + fontSize = 14.sp, |
| 80 | + color = Color(0xFFD16767) |
| 81 | + ) |
| 82 | + ) |
| 83 | + } |
| 84 | + }, |
| 85 | + itemContent = { music -> |
| 86 | + Card( |
| 87 | + modifier = Modifier.fillMaxWidth(), |
| 88 | + shape = MaterialTheme.shapes.medium, |
| 89 | + elevation = CardDefaults.cardElevation(4.dp) |
| 90 | + ) { |
| 91 | + Column(modifier = Modifier.padding(16.dp)) { |
| 92 | + Text(music.title, style = MaterialTheme.typography.titleMedium) |
| 93 | + Text(music.artist, style = MaterialTheme.typography.bodyMedium) |
| 94 | + } |
| 95 | + } |
| 96 | + }, |
| 97 | + timeLineDot = { |
| 98 | + Box( |
| 99 | + modifier = Modifier |
| 100 | + .size(24.dp) |
| 101 | + .background( |
| 102 | + Color.Gray, |
| 103 | + shape = CircleShape |
| 104 | + ) |
| 105 | + ) |
| 106 | + } |
| 107 | + ) |
| 108 | +} |
| 109 | +``` |
| 110 | + |
| 111 | +##### Basic Usage - LazyRow |
| 112 | +```kotlin |
| 113 | +@Composable |
| 114 | +fun TimeLineRowExample() { |
| 115 | + val musicList = remember { MusicRepo().musicList } |
| 116 | + val sortedMusicList = musicList.sortedWith( |
| 117 | + compareBy( |
| 118 | + { it.year.toIntOrNull() ?: 0 }, |
| 119 | + { it.month.toIntOrNull() ?: 0 } |
| 120 | + ) |
| 121 | + ) |
| 122 | + |
| 123 | + StickyTimeLineLazyRow( |
| 124 | + items = sortedMusicList, |
| 125 | + lineColor = Color(0xFF51ae45), |
| 126 | + lineWidth = 2.dp, |
| 127 | + groupBy = { it.year }, |
| 128 | + makeHeaderItem = { key, _ -> key }, |
| 129 | + headerContent = { year -> |
| 130 | + Column( |
| 131 | + modifier = Modifier |
| 132 | + .wrapContentSize() |
| 133 | + .padding(horizontal = 8.dp) |
| 134 | + ) { |
| 135 | + Text( |
| 136 | + text = year, |
| 137 | + style = TextStyle( |
| 138 | + fontSize = 18.sp, |
| 139 | + fontWeight = FontWeight.Bold, |
| 140 | + color = Color(0xFF414FCA) |
| 141 | + ) |
| 142 | + ) |
| 143 | + Text( |
| 144 | + text = "Popular Music", |
| 145 | + style = TextStyle( |
| 146 | + fontSize = 14.sp, |
| 147 | + color = Color(0xFFD16767) |
| 148 | + ) |
| 149 | + ) |
| 150 | + } |
| 151 | + }, |
| 152 | + itemContent = { music -> |
| 153 | + Card( |
| 154 | + modifier = Modifier.wrapContentWidth(), |
| 155 | + shape = MaterialTheme.shapes.medium, |
| 156 | + elevation = CardDefaults.cardElevation(4.dp) |
| 157 | + ) { |
| 158 | + Column(modifier = Modifier.padding(16.dp)) { |
| 159 | + Text(music.title, style = MaterialTheme.typography.titleMedium) |
| 160 | + Text(music.artist, style = MaterialTheme.typography.bodyMedium) |
| 161 | + } |
| 162 | + } |
| 163 | + }, |
| 164 | + dotContent = { _ -> |
| 165 | + Box( |
| 166 | + modifier = Modifier |
| 167 | + .size(24.dp) |
| 168 | + .background( |
| 169 | + Color.Gray, |
| 170 | + shape = CircleShape |
| 171 | + ) |
| 172 | + ) |
| 173 | + } |
| 174 | + ) |
| 175 | +} |
| 176 | +``` |
| 177 | + |
| 178 | +##### Parameters - StickyTimeLineLazyColumn |
| 179 | + |
| 180 | +| Parameter | Type | Default | Description | |
| 181 | +|-----------|------|---------|-------------| |
| 182 | +| `modifier` | `Modifier` | `Modifier` | Modifier for the component | |
| 183 | +| `items` | `List<T>` | - | List of items to display in the timeline | |
| 184 | +| `groupBy` | `(T) -> String` | - | Function to group items by section (returns section key) | |
| 185 | +| `makeHeaderItem` | `(key: String, items: List<T>) -> G` | - | Function to create header item from section key and items | |
| 186 | +| `generateItemKey` | `(T) -> Any` | `{ it.hashCode() }` | Function to generate unique key for each item (for recomposition optimization) | |
| 187 | +| `contentBackgroundColor` | `Color` | `Color.White` | Background color of the content area | |
| 188 | +| `lineColor` | `Color` | `Color.Blue` | Color of the timeline line | |
| 189 | +| `lineWidth` | `Dp` | `2.dp` | Width of the timeline line | |
| 190 | +| `verticalSpaceBy` | `Dp` | `12.dp` | Vertical spacing between items | |
| 191 | +| `timeLineHorizontalPadding` | `Dp` | `0.dp` | Horizontal padding for the timeline | |
| 192 | +| `timeLineDot` | `@Composable () -> Unit` | - | Composable for timeline dot | |
| 193 | +| `sectionHeader` | `@Composable (headerItem: G) -> Unit` | - | Composable for section header | |
| 194 | +| `itemContent` | `@Composable (item: T) -> Unit` | - | Composable content for each item | |
| 195 | + |
| 196 | +##### Parameters - StickyTimeLineLazyRow |
| 197 | + |
| 198 | +| Parameter | Type | Default | Description | |
| 199 | +|-----------|------|---------|-------------| |
| 200 | +| `modifier` | `Modifier` | `Modifier` | Modifier for the component | |
| 201 | +| `items` | `List<T>` | - | List of items to display in the timeline | |
| 202 | +| `groupBy` | `(T) -> String` | - | Function to group items by section (returns section key) | |
| 203 | +| `makeHeaderItem` | `(key: String, items: List<T>) -> G` | - | Function to create header item from section key and items | |
| 204 | +| `generateItemKey` | `(T) -> Any` | `{ it.hashCode() }` | Function to generate unique key for each item (for recomposition optimization) | |
| 205 | +| `headerContent` | `@Composable (headerItem: G) -> Unit` | - | Composable for section header | |
| 206 | +| `itemContent` | `@Composable (item: T) -> Unit` | - | Composable content for each item | |
| 207 | +| `dotContent` | `@Composable (group: String) -> Unit` | Default blue circle | Composable for timeline dot | |
| 208 | +| `lineColor` | `Color` | `Color.Blue` | Color of the timeline line | |
| 209 | +| `lineWidth` | `Dp` | `2.dp` | Width of the timeline line | |
| 210 | +| `horizontalSpaceBy` | `Dp` | `12.dp` | Horizontal spacing between items | |
| 211 | +| `contentPaddingValues` | `PaddingValues` | `PaddingValues(horizontal = 8.dp)` | Padding values for the content | |
| 212 | + |
| 213 | +#### View System Usage |
| 214 | + |
| 215 | +##### activity_main.xml |
29 | 216 | ```xml
|
30 | 217 | <?xml version="1.0" encoding="utf-8"?>
|
31 | 218 | <android.support.constraint.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
|
0 commit comments