Deepak Gahlot

    Deepak Gahlot

    1 year ago
    Is there a way in LazyColumn to scroll to a particular position in an Item. I'm working on building Expandable Item List. And each Expandable Card contains multiple Questions that user has to fill the answer. Once the user submit the answer, I check the validations from server and show the error is respective answer. Now i need a way to scroll to that particular answer and then keep on moving to the next error. Before COMPOSE i used to do this via requestFocus using a recyclerview. i have been going through documentation of compose and unable to find a way to build this
    s

    Sam

    1 year ago
    We are facing the same challenges with
    LazyColumn
    in our chat app, the
    LazyListState
    api is very limited with
    smoothScrollBy
    and
    snapToItemIndex
    and there is not much you can do at this point until the api becomes more robust
    Dominaezzz

    Dominaezzz

    1 year ago
    Are you using Matrix in your chat app?
    s

    Sam

    1 year ago
    what is matrix?
    Dominaezzz

    Dominaezzz

    1 year ago
    s

    Sam

    1 year ago
    looks very cool, but no we are not using it
    what’s the connection to jetpack compose though, or is it a tangent question?
    Dominaezzz

    Dominaezzz

    1 year ago
    Tangent question. Was curious.
    s

    Sam

    1 year ago
    our platform is built from the ground, specialized to handle chatrooms with 100,000+ members
    Dominaezzz

    Dominaezzz

    1 year ago
    I'll DM you.
    Andrey Kulikov

    Andrey Kulikov

    1 year ago
    @Sam what use cases exactly you can’t solve with the current api? in the next release there would be a new method which allows to scroll to an item with animation
    s

    Sam

    1 year ago
    Hi @Andrey Kulikov thanks for asking about
    LazyColumn
    scroll api. These are issues that currently inhibit a full fledged chat app: • maintain precise scroll position after items are added/removed to top/bottom/middle of LazyColumn. Imagine a chat app like Slack with infinite scroll, users deleting messages etc. Right now when we infinite scroll, there is jitter of moving back to the correct scroll position using the api in all these cases. • Access to cell/item measurements so that it’s possible to get a precise scroll location. For example if I want to jump to the last item in a (non-reversed) list, I first need to understand the size of the viewport and size of last few items to get to the right spot. Alternatively, please provide the ability to set the desired
    start/middle/end
    when using
    snapToItemIndex
    because right now there’s not enough fidelity
    Deepak Gahlot

    Deepak Gahlot

    1 year ago
    Hello @Andrey Kulikov in our scenario we have a list of categories in a list. And each category has a huge list of question itself which we are showing after the user expands the heading(Main Category). Once the user fills the fields , we validate the answers and show the error if any. Now the challenge that we are facing with current scroll api in LazyColumn/Row is that we can only scroll to the Item which is the main heading but we want to bring the question for which input has the answer in that Item. I have an option to provide an offset and scroll to that particular question, but that is not that refined. We are trying to refine our offset calculation logic but is there could have a functionality like requestFocus in the Recycler View it would be nice!!!
    Archie

    Archie

    1 year ago
    @Deepak Gahlot, I have quite the same scenario. The problem is that, my TextFields are inside a 
    Column
     which is inside LazyColumn's 
    item()
    . I could call 
    LazyState.animateScrollToItem()
     but I don't know how to get the correct 
    Offset
     to properly position the focused 
    TextField
    .
    Deepak Gahlot

    Deepak Gahlot

    1 year ago
    @Archie Ya, I hope the compose dev team is working on something which helps us in solving this challenge.
    Otherwise I think the only way around this will be building a robust offset calculation logic
    s

    Sam

    1 year ago
    @Andrey Kulikov hey there, any word on what might be coming to the scrollable apis to help with these more advanced scenarios? Hard to tell at the moment if we should go deep and hack with what is available now, or if we should wait for future improvements?
    Andrey Kulikov

    Andrey Kulikov

    1 year ago
    Hi @Sam. Please file a bug for the first use case, I think we can fix it. For the second one we will not be adding a new api for 1.0 at least. The focus was to make the use cases like this possible, see how it is used and what extensions on top are useful and add some of them. So feel free to file a feedback for this one as well. but we won’t add them in the short term I think
    s

    Sam

    1 year ago
    Thanks for the feedback, since it’s hard to tell which ones in particular to take action on, can you comment on specifically: 1.) Maintaining scroll position without jitter when items change (adding, removing, updating items in beginning/middle/end of list) 2.) Being able to scroll to a more precise point (i.e. top / middle / bottom) of an item 3.) Being able to scroll to a more precise point (or conduct precise animations) by getting access to item height measurements
    Andrey Kulikov

    Andrey Kulikov

    1 year ago
    for the first one I think we should improve it. I think when you use keys - https://developer.android.com/jetpack/compose/lists#item-keys we should remember what was the key, not position of the first visible element. and when this element was moved to the other position we should still consider this item as a first visible. if you file a bug for it I can take a look on that
    for 2 and 3 I don’t think we will add anything in the near feature as it is doable already, you can write your own extension on
    LazyListState
    which finds the item in the
    layoutInfo
    and calculates the needed offset based on the size of the item