Skip to content

kosenda/AutoSizeTable

Repository files navigation

CircleCI Renovate 

AutoSizeTable

Jetpack Compose library to easily create tables with each item resized。

Warning

Poor performance

▪ Sample

4b013745-a04e-42d6-9cb1-1286716ef1ee.mp4

@Composable
fun SampleScreen() {
val colorScheme = MaterialTheme.colorScheme
var typeIndex by remember { mutableIntStateOf(0) }
var numMailRowIcons by remember { mutableIntStateOf(1) }
var numMailColumnIcons by remember { mutableIntStateOf(1) }
// fixedTopSize to fixedStartSize
val type = listOf(
1 to 1,
1 to 0,
0 to 1,
0 to 0,
1 to 2,
2 to 2,
)
Surface(
color = MaterialTheme.colorScheme.background,
) {
Column {
Row(
modifier = Modifier
.horizontalScroll(rememberScrollState()),
) {
Button(
onClick = {
typeIndex = (typeIndex + 1) % type.size
},
modifier = Modifier.padding(start = 8.dp, top = 8.dp),
) {
Text("Switch fixed size")
}
Button(
onClick = {
numMailRowIcons = (numMailRowIcons) % MAX_NUM_OF_MAIL_ICONS + 1
},
modifier = Modifier.padding(start = 8.dp, top = 8.dp),
) {
Text("Switch num of row mail icons")
}
Button(
onClick = {
numMailColumnIcons = (numMailColumnIcons) % MAX_NUM_OF_MAIL_ICONS + 1
},
modifier = Modifier.padding(start = 8.dp, top = 8.dp, end = 8.dp),
) {
Text("Switch num of column mail icons")
}
}
AutoSizeTable(
modifier = Modifier.padding(all = 8.dp),
outlineColor = colorScheme.outline,
content = List(NUM_OF_ITEMS_IN_EACH_COLUMN) { columnId ->
List(NUM_OF_ITEMS_IN_EACH_ROW) { rowId ->
{
if (rowId == 0 && columnId % 2 == 0) {
Column {
repeat(numMailColumnIcons) {
Row {
repeat(numMailRowIcons) {
Icon(
imageVector = Icons.Default.MailOutline,
contentDescription = null,
modifier = Modifier
.padding(4.dp)
.size(48.dp),
)
}
}
}
}
} else {
Text(
text = "rowId: $rowId \ncolumnId: $columnId",
modifier = Modifier.padding(8.dp),
fontWeight = if (columnId < type[typeIndex].first) {
FontWeight.Bold
} else {
FontWeight.Normal
},
)
}
}
}
},
backgroundColor = { columnId, rowId ->
when {
columnId in 0..<type[typeIndex].first -> {
colorScheme.primaryContainer
}
rowId in 0..<type[typeIndex].second -> {
colorScheme.tertiaryContainer
}
columnId % 2 == 0 -> colorScheme.surface
else -> colorScheme.inverseOnSurface
}
},
contentAlignment = { _, _ -> Alignment.Center },
fixedTopSize = type[typeIndex].first,
fixedStartSize = type[typeIndex].second,
)
}
}
}

▪ How to setup

Step 1. Add the JitPack repository to your build file

Add it in your root build.gradle at the end of repositories:

dependencyResolutionManagement {
  repositoriesMode.set(RepositoriesMode.FAIL_ON_PROJECT_REPOS)
  repositories {
    mavenCentral()
    maven { url = uri("https://jitpack.io") }
  }
}

Step 2. Add the dependency

See release page for <version>

dependencies {
  implementation("com.github.kosenda:AutoSizeTable:<version>")
}

About

Jetpack Compose library to easily create tables with each item resized。 (**Poor performance**)

Topics

Resources

License

Stars

Watchers

Forks

Packages

No packages published