Hello :slightly_smiling_face: I am working on a We...
# compose-wear
p
Hello 🙂 I am working on a Wear Compose project. I am a beginner confused about the ScalingLazyColumn mechanics. More precisely ScalingLazyColumn parameters:
anchorType
,
autoCentering
and
flingBehavior
. I thought the snapping behavior (described in
anchorType
docs) would do the same as
flingBehavior
(
ScalingLazyColumnDefaults.snapFlingBehavior
). What is the difference between those two and why don't they both work the same? Also does
autoCentering
work only for centering of the first and the last element in a ScalingLazyColumn? Thanks
👍 1
j
anchorType determines whether the Top or the Center of an item is used for snapping if enabled and autoCentering. autoCentering is used to auto calculate the padding (top and bottom) needed to make sure the list items can be correctly positioned. By default the SLC will add correct padding for the 2nd (index == 1) and last items to be able to be positioned in the center of the screen.
The default of the 2nd item is because our UX guidance is that you have a heading item as the first (index = 0) item of the list
and that you don't typically want to move that to the center of the screen
p
Thanks John for the answer. Is there a quick way to enable snapping? Or where to look at for enabling it?
j
yes - really easy 1 sec
p
Is it
flingBehavior
(
ScalingLazyColumnDefaults.snapFlingBehavior
)?
j
yes
Copy code
@Sampled
@Composable
fun SimpleScalingLazyColumnWithSnap() {
    val state = rememberScalingLazyListState()
    ScalingLazyColumn(
        modifier = Modifier.fillMaxWidth(),
        state = state,
        flingBehavior = ScalingLazyColumnDefaults.snapFlingBehavior(state = state)
    ) {
        item {
            ListHeader {
                Text(text = "List Header")
            }
        }
        items(20) {
            Chip(
                onClick = { },
                label = { Text("List item $it") },
                colors = ChipDefaults.secondaryChipColors()
            )
        }
    }
}
p
Ok great! Thank you 🙂
j
no problem