Skip to content

Commit f31d28e

Browse files
committed
Add dependency on fastscroller, use their scrollbar, remove platform-specific code
1 parent 8e39544 commit f31d28e

8 files changed

Lines changed: 39 additions & 96 deletions

File tree

data-table/src/commonMain/kotlin/com/seanproctor/datatable/paging/BasicPaginatedDataTable.kt

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -44,9 +44,7 @@ fun BasicPaginatedDataTable(
4444
) {
4545
val start = state.pageIndex * state.pageSize
4646
val scope = PaginatedRowScope(start, start + state.pageSize, this)
47-
with(scope) {
48-
content()
49-
}
47+
content(scope)
5048
if (state.count != scope.index) {
5149
state.count = scope.index
5250
}

demo-common/build.gradle.kts

Lines changed: 1 addition & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -11,20 +11,9 @@ kotlin {
1111
dependencies {
1212
implementation(project(":data-table-material3"))
1313
implementation(compose.material3)
14+
implementation(libs.fastscroller.m3)
1415
}
1516
}
16-
17-
val skikoMain by creating {
18-
dependsOn(commonMain)
19-
}
20-
21-
val jvmMain by getting {
22-
dependsOn(skikoMain)
23-
}
24-
25-
val jsMain by getting {
26-
dependsOn(skikoMain)
27-
}
2817
}
2918
}
3019

demo-common/src/androidMain/kotlin/com/seanproctor/datatable/demo/Scrollbar.android.kt

Lines changed: 0 additions & 11 deletions
This file was deleted.

demo-common/src/commonMain/kotlin/com/seanproctor/datatable/demo/App.kt

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,9 @@ import com.seanproctor.datatable.material3.DataTable
3131
import com.seanproctor.datatable.material3.LazyPaginatedDataTable
3232
import com.seanproctor.datatable.material3.PaginatedDataTable
3333
import com.seanproctor.datatable.paging.rememberPaginatedDataTableState
34+
import io.github.oikvpqya.compose.fastscroller.HorizontalScrollbar
35+
import io.github.oikvpqya.compose.fastscroller.VerticalScrollbar
36+
import io.github.oikvpqya.compose.fastscroller.material3.defaultMaterialScrollbarStyle
3437
import kotlin.math.min
3538

3639
@OptIn(ExperimentalMaterial3Api::class)
@@ -125,12 +128,14 @@ fun App(onRowClick: (Int) -> Unit) {
125128
println("total size: ${scrollState.horizontalScrollState.totalSize}")
126129
}
127130
VerticalScrollbar(
128-
scrollState.verticalScrollState,
129-
Modifier.fillMaxHeight().align(Alignment.CenterEnd)
131+
adapter = rememberScrollbarAdapter(scrollState.verticalScrollState),
132+
style = defaultMaterialScrollbarStyle(),
133+
modifier = Modifier.fillMaxHeight().align(Alignment.CenterEnd),
130134
)
131135
HorizontalScrollbar(
132-
scrollState.horizontalScrollState,
133-
Modifier.fillMaxWidth().align(Alignment.BottomCenter)
136+
adapter = rememberScrollbarAdapter(scrollState.horizontalScrollState),
137+
style = defaultMaterialScrollbarStyle(),
138+
modifier = Modifier.fillMaxWidth().align(Alignment.BottomCenter)
134139
)
135140
}
136141
} else if (selectedIndex == 1) {
Lines changed: 25 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,33 @@
11
package com.seanproctor.datatable.demo
22

33
import androidx.compose.runtime.Composable
4+
import androidx.compose.runtime.remember
45
import androidx.compose.ui.Modifier
56
import com.seanproctor.datatable.DataTableScrollState
7+
import io.github.oikvpqya.compose.fastscroller.ScrollbarAdapter
8+
import kotlin.math.roundToInt
69

710
@Composable
8-
expect fun VerticalScrollbar(scrollState: DataTableScrollState, modifier: Modifier)
11+
fun rememberScrollbarAdapter(scrollState: DataTableScrollState): ScrollbarAdapter {
12+
return remember(scrollState) { DataTableScrollbarAdapter(scrollState) }
13+
}
914

10-
@Composable
11-
expect fun HorizontalScrollbar(scrollState: DataTableScrollState, modifier: Modifier)
15+
internal class DataTableScrollbarAdapter(
16+
private val scrollState: DataTableScrollState
17+
) : ScrollbarAdapter {
18+
override val scrollOffset: Double get() = scrollState.offset.toDouble()
19+
20+
override suspend fun scrollTo(scrollOffset: Double) {
21+
scrollState.scrollTo(scrollOffset.roundToInt())
22+
}
23+
24+
override val contentSize: Double
25+
// This isn't strictly correct, as the actual content can be smaller
26+
// than the viewport when scrollState.maxValue is 0, but the scrollbar
27+
// doesn't really care as long as contentSize <= viewportSize; it's
28+
// just not showing itself
29+
get() = scrollState.totalSize.toDouble()
30+
31+
override val viewportSize: Double
32+
get() = scrollState.viewportSize.toDouble()
33+
}

demo-common/src/iosMain/kotlin/com/seanproctor/datatable/demo/Scrollbar.ios.kt

Lines changed: 0 additions & 11 deletions
This file was deleted.

demo-common/src/skikoMain/kotlin/com/seanproctor/datatable/demo/Scrollbar.jvm.kt

Lines changed: 0 additions & 51 deletions
This file was deleted.

gradle/libs.versions.toml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,18 +18,20 @@ datatable-android-application = { id = "datatable.android.application" }
1818

1919
[versions]
2020

21-
activityCompose = "1.10.0"
21+
activityCompose = "1.10.1"
2222
androidGradlePlugin = "8.7.3"
2323
androidTools = "31.7.3"
2424
androidxLintGradle = "1.0.0-alpha03"
2525
compose = "1.7.3"
26+
fastscroller = "0.3.0"
2627
kotlin = "2.1.10"
2728
truth = "1.4.4"
2829
vanniktech = "0.30.0"
2930

3031
[libraries]
3132

3233
activity-compose = { module = "androidx.activity:activity-compose", version.ref = "activityCompose" }
34+
fastscroller-m3 = { module = "io.github.oikvpqya.compose.fastscroller:fastscroller-material3", version.ref = "fastscroller" }
3335
truth = { group = "com.google.truth", name = "truth", version.ref = "truth" }
3436

3537
# Dependencies of the included build-logic

0 commit comments

Comments
 (0)