From f28c85cd92669dde5de119dc8485f4de92d0d3d7 Mon Sep 17 00:00:00 2001 From: kosenda Date: Sun, 10 Dec 2023 12:05:08 +0900 Subject: [PATCH 1/2] feature: enable vertical overscroll --- .../java/ksnd/autosizetable/AutoSizeTable.kt | 145 +++++++++--------- 1 file changed, 75 insertions(+), 70 deletions(-) diff --git a/autosizetable/src/main/java/ksnd/autosizetable/AutoSizeTable.kt b/autosizetable/src/main/java/ksnd/autosizetable/AutoSizeTable.kt index 4dc95f9..09f70a3 100644 --- a/autosizetable/src/main/java/ksnd/autosizetable/AutoSizeTable.kt +++ b/autosizetable/src/main/java/ksnd/autosizetable/AutoSizeTable.kt @@ -69,50 +69,50 @@ fun AutoSizeTable( ) } - // OverScroll behavior is a bit strange due to set scrollState for each column and each row. - // Therefore, the OverScroll effect is disabled. - CompositionLocalProvider( - LocalOverscrollConfiguration provides null, - ) { - MeasureTable( - modifier = modifier, - items = content, - ) { tableItemSize -> - Column( - modifier = if (isFixedTop.not() && isFixedStart.not()) { - Modifier - .horizontalScroll(horizontalScrollState) - .verticalScroll(verticalScrollState) - } else { - Modifier - }, - ) { - // Fixed top part - Row { + MeasureTable( + modifier = modifier, + items = content, + ) { tableItemSize -> + Column( + modifier = if (isFixedTop.not() && isFixedStart.not()) { + Modifier + .horizontalScroll(horizontalScrollState) + .verticalScroll(verticalScrollState) + } else { + Modifier + }, + ) { + // Fixed top part + Row { - // Fixed top and left part - Column { - content.take(fixedTopSize).forEachIndexed { columnId, columnList -> - Row { - columnList.take(fixedStartSize).forEachIndexed { rowId, item -> - Box( - modifier = Modifier - .size( - width = tableItemSize.columnWidthSize[rowId], - height = tableItemSize.rowHeightSize[columnId], - ) - .background(color = backgroundColor(columnId, rowId)) - .drawBehind(onDraw = outlineOnDraw), - contentAlignment = contentAlignment(columnId, rowId), - ) { - item() - } + // Fixed top and left part + Column { + content.take(fixedTopSize).forEachIndexed { columnId, columnList -> + Row { + columnList.take(fixedStartSize).forEachIndexed { rowId, item -> + Box( + modifier = Modifier + .size( + width = tableItemSize.columnWidthSize[rowId], + height = tableItemSize.rowHeightSize[columnId], + ) + .background(color = backgroundColor(columnId, rowId)) + .drawBehind(onDraw = outlineOnDraw), + contentAlignment = contentAlignment(columnId, rowId), + ) { + item() } } } } + } - // Fixed top part + // Fixed top part + // OverScroll behavior is a bit strange due to set scrollState for each column and each row. + // Therefore, the OverScroll effect is disabled. + CompositionLocalProvider( + LocalOverscrollConfiguration provides null, + ) { Column( modifier = if (isFixedTop) { Modifier.horizontalScroll(horizontalScrollState) @@ -142,47 +142,52 @@ fun AutoSizeTable( } } } + } - // Unfixed top part - Row { + // Unfixed top part + Row( + modifier = if (isFixedStart.not() && isFixedTop.not()) { + Modifier + } else { + Modifier.verticalScroll(verticalScrollState) + }, + ) { - // Fixed left part - Column( - modifier = if (isFixedStart) { - Modifier.verticalScroll(verticalScrollState) - } else { - Modifier - }, - ) { - content.takeLast(content.size - fixedTopSize) - .forEachIndexed { columnId, columnList -> - Row { - columnList.take(fixedStartSize).forEachIndexed { rowId, item -> - Box( - modifier = - Modifier - .size( - width = tableItemSize.columnWidthSize[rowId], - height = tableItemSize.rowHeightSize[columnId + fixedTopSize], - ) - .background( - color = backgroundColor(columnId + fixedTopSize, rowId), - ) - .drawBehind(onDraw = outlineOnDraw), - contentAlignment = contentAlignment(columnId + fixedTopSize, rowId), - ) { - item() - } + // Fixed left part + Column { + content.takeLast(content.size - fixedTopSize) + .forEachIndexed { columnId, columnList -> + Row { + columnList.take(fixedStartSize).forEachIndexed { rowId, item -> + Box( + modifier = + Modifier + .size( + width = tableItemSize.columnWidthSize[rowId], + height = tableItemSize.rowHeightSize[columnId + fixedTopSize], + ) + .background( + color = backgroundColor(columnId + fixedTopSize, rowId), + ) + .drawBehind(onDraw = outlineOnDraw), + contentAlignment = contentAlignment(columnId + fixedTopSize, rowId), + ) { + item() } } } - } + } + } - // Unfixed part + // Unfixed part + CompositionLocalProvider( + // Disable horizontal OverScrollEffect + // because it cannot be common OverScrollEffect and results in strange behavior. + LocalOverscrollConfiguration provides null, + ) { Column( modifier = if (isFixedTop || isFixedStart) { Modifier - .verticalScroll(verticalScrollState) .horizontalScroll(horizontalScrollState) } else { Modifier From b3f207a7a8e2d0ae1acb3edb7bf427f1819890e0 Mon Sep 17 00:00:00 2001 From: kosenda Date: Sun, 10 Dec 2023 12:08:35 +0900 Subject: [PATCH 2/2] chore: fix comment --- .../src/main/java/ksnd/autosizetable/AutoSizeTable.kt | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/autosizetable/src/main/java/ksnd/autosizetable/AutoSizeTable.kt b/autosizetable/src/main/java/ksnd/autosizetable/AutoSizeTable.kt index 09f70a3..7c053a0 100644 --- a/autosizetable/src/main/java/ksnd/autosizetable/AutoSizeTable.kt +++ b/autosizetable/src/main/java/ksnd/autosizetable/AutoSizeTable.kt @@ -108,9 +108,9 @@ fun AutoSizeTable( } // Fixed top part - // OverScroll behavior is a bit strange due to set scrollState for each column and each row. - // Therefore, the OverScroll effect is disabled. CompositionLocalProvider( + // Disable horizontal OverScrollEffect + // because it cannot be common OverScrollEffect and results in strange behavior. LocalOverscrollConfiguration provides null, ) { Column(