I have a list with expandable items, when I click ...
# compose
z
I have a list with expandable items, when I click on the last item I would like the list to scroll up and show the expanded item, how can I achieve that?
1
n
i think maybe you need to call
listState.animateScrollToItem(lastIndex)
after clicking on the last item
z
This scrolls to the item top, leaving the expanded portion below the screen. Trying to use offset, however, is tricky as it's hard to get the valid height after expansion...
n
it make sense, i just tried it and it seems to only scroll to the bottom of the unexpanded part, there may be measurements involved and I'm curious how this needs to be resolved too..🤔
👍 1
z
I tried using .onGloballyPositiond and get the size but at the time of the tap I get the pre expanded size, perhaps if I can get some callback from the expension animation...
d
RelocationRequester
seems to be more appropriate for scrolling a certain component into view. We can invoke it in the
finishedListener
that we can pass to
animateContentSize
r
If you use the 1.1 alpha branch, then if you use a Modifier.focusable, it will automatically use relocationRequester under the hood to bring the focused item into view.
z
This approach seems right but unfortunately it crashes with
kotlin.UninitializedPropertyAccessException: lateinit property coordinates has not been initialized
When tapping for the second time, probably since we
remember { RelocationRequester() }
and not some mutable state. Also it brings the middle of the view to front and some of it is still hidden, perhaps this method should be called on a callback from the AnimatedVisibility, i will further investigate.