https://kotlinlang.org logo
#compose
Title
# compose
d

Deepak Gahlot

02/23/2021, 10:59 AM
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
d

Dominaezzz

02/23/2021, 8:16 PM
Are you using Matrix in your chat app?
s

Sam

02/23/2021, 8:17 PM
what is matrix?
d

Dominaezzz

02/23/2021, 8:18 PM
s

Sam

02/23/2021, 8:20 PM
looks very cool, but no we are not using it
what’s the connection to jetpack compose though, or is it a tangent question?
d

Dominaezzz

02/23/2021, 8:24 PM
Tangent question. Was curious.
s

Sam

02/23/2021, 8:25 PM
our platform is built from the ground, specialized to handle chatrooms with 100,000+ members
d

Dominaezzz

02/23/2021, 8:32 PM
I'll DM you.
a

Andrey Kulikov

02/23/2021, 11:35 PM
@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
d

Deepak Gahlot

03/01/2021, 8:07 AM
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!!!
👍 1
a

Archie

03/03/2021, 5:30 AM
@Deepak Gahlot, I have quite the same scenario. The problem is that, my `TextField`s 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
.
d

Deepak Gahlot

03/03/2021, 5:32 AM
@Archie Ya, I hope the compose dev team is working on something which helps us in solving this challenge.
👍 2
Otherwise I think the only way around this will be building a robust offset calculation logic
a

Andrey Kulikov

03/09/2021, 8:00 PM
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

03/09/2021, 8:04 PM
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
a

Andrey Kulikov

03/09/2021, 11:42 PM
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