pushpalroy / JetLime

A Kotlin Multiplatform library to display a timeline view in Android. 🍋
https://jetlime.pushpalroy.com
MIT License
431 stars 25 forks source link

Way to scroll to particular JetLimeItem? #10

Closed joreilly closed 2 years ago

joreilly commented 2 years ago

Is there any way right now to be able to scroll to particular JetLimeItem in the list? I'm using for bus stops on particular route and ideally would like, as data is updated, to scroll to JetLimeItem for the next stop a bus is due to arrive at.

pushpalroy commented 2 years ago

Hi, @joreilly Yes. The JetLimeView already takes a LazyListState!

So you hold a LazyListState and pass it:

val listState = rememberLazyListState()
JetLimeView(
        jetLimeItemsModel = jetLimeItemsModel,
        jetLimeViewConfig = jetTimeLineViewConfig,
        listState = listState
      )

And then: listState.scrollToItem(index = 4)

This will scroll to the 4th item of the list.

In sample AnimatedTimeLine, I have shown how to use the list state to always keep the list scrolled till the bottom, by using: listState.scrollToItem(jetLimeItemsModel.items.size)

Hope this will help you to scroll to the particular bus stop item! 😃

joreilly commented 2 years ago

nice, thanks!