oleksandrbalan / lazytable

Lazy layout to display columns and rows of data on the two directional plane.
Apache License 2.0
261 stars 12 forks source link

Programatically scroll to a column #9

Closed ikerfah closed 10 months ago

ikerfah commented 10 months ago

Hi, Thanks foe the great work of that library!

Is it possible to programmatically scroll the table in a direction? let's say Horizontally. where I need to scroll to a specific items or scroll to the very right of the table

UPDATE Checked the code and managed to figure it out, I will keep it here in case someone needed it! 1.

val lazyTableState: LazyTableState = rememberLazyTableState()

2.

LazyTable(
...
state = lazyTableState
)

3.

 LaunchedEffect(Unit) {
    lazyTableState.snapToCell(column = 6, row = 0)
}
oleksandrbalan commented 10 months ago

Thx 🤗

Yeap, you could use a state to animate-to or snap-to the specific cell.

If you do want to scroll the whole table (no matter on which row the user is), you could use underlying state of the MinaBox layout and animate to the max X value:

val scope = rememberCoroutineScope()
val state = rememberLazyTableState()

Button(
    onClick = {
        scope.launch {
            state.animateToCell(
                column = 4,
                row = 4,
            )
        }
    }
) {
    Text("Center on cell (4, 4)")
}

Button(
    onClick = {
        scope.launch {
            state.minaBoxState.animateTo(
                x = state.minaBoxState.translate?.maxX ?: 0f
            )
        }
    }
) {
    Text("Focus last column")
}

https://github.com/oleksandrbalan/lazytable/assets/20944869/2d86543c-e81e-47bb-92da-43b5cc1669ec