You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
This repository has been archived by the owner on May 1, 2024. It is now read-only.
I'd like to use a CollectionView for displaying chat messages, where I want it to scroll to the end of the messages as an initial state.
ItemsUpdatingScrollMode="KeepLastItemInView" doesn't work when the list is initially loaded, and only seems to work when adding new items to it.
So repro would be to have a CollectionView with an ItemsSource (with enough items to have it scroll), and ItemsUpdatingScrollMode="KeepLastItemInView". I also have MeasureAllItems as item sizing strategy, don't know if it affects.
Workaround attempt:
I tried to ScrollTo the end manually, but it takes an arbitrary amount of time before ScrollTo actually does anything (I guess it's populating the elements asynchronously from the ItemsSource), so I listen to ChildAdded instead to know when it has started to actually populate data. But even there I need to wait arbitrarily for ScrollTo to actually do anything. I really dislike adding this much hacks and random delays to get a list to scroll to the bottom. I keep an overlay on top of the collection view until it's loaded fully. But the drawback with this approach is that I can't know how long to delay the operations, and they are surely device and list contents specific. I've had to increase the delays to hide the issues and it's impossible to get it right. My current hack is:
// TEMP HACK! ItemsUpdatingScrollMode="KeepLastItemInView" doesn't work when collection view is populated,// so wait until one element has been added and manually scroll to bottom.// I also tried to manually scroll to bottom when collection gets data, but that is also too early.// TODO: remove this nonsense once Xamarin fixes KeepLastItemInView when creating collection, or fixes// ScrollTo in conjunction with a collection being populated.privateasyncvoidChatMessages_ChildAdded(objectsender,ElementEventArgse){if(this.tempHackHasRequestedInitialScrollToBottom){this.tempHackHasRequestedInitialScrollToBottom=false;awaitTask.Delay(17);// HACK! trying to scroll while items are being added seems to be ignoredthis.ScrollToLastMessage(false);awaitTask.Delay(60);// HACK: scroll doesn't seem to be immediate and it doesn't return a Task to await on...this.HasFullyLoadedChatMessages=true;}}
Xamarin.Forms 5-pre3, iOS (didn't test on Android).
The text was updated successfully, but these errors were encountered:
PureWeen
added
s/needs-info ❓
A question has been asked that requires an answer before work can continue on this issue.
s/needs-repro ❔
This reported issue doesn't include a sample project reproducing the issue. Please provide one.
and removed
s/needs-info ❓
A question has been asked that requires an answer before work can continue on this issue.
s/needs-repro ❔
This reported issue doesn't include a sample project reproducing the issue. Please provide one.
labels
Oct 27, 2020
Just in case -- in your tests: please make sure to set the ItemsSource to a real binding, preferably to an ObservableCollection, as I am starting to think some issues can not be reproduced with an "inline" items source.
Hi.
I'd like to use a CollectionView for displaying chat messages, where I want it to scroll to the end of the messages as an initial state.
ItemsUpdatingScrollMode="KeepLastItemInView" doesn't work when the list is initially loaded, and only seems to work when adding new items to it.
So repro would be to have a CollectionView with an ItemsSource (with enough items to have it scroll), and ItemsUpdatingScrollMode="KeepLastItemInView". I also have MeasureAllItems as item sizing strategy, don't know if it affects.
Workaround attempt:
I tried to ScrollTo the end manually, but it takes an arbitrary amount of time before ScrollTo actually does anything (I guess it's populating the elements asynchronously from the ItemsSource), so I listen to ChildAdded instead to know when it has started to actually populate data. But even there I need to wait arbitrarily for ScrollTo to actually do anything. I really dislike adding this much hacks and random delays to get a list to scroll to the bottom. I keep an overlay on top of the collection view until it's loaded fully. But the drawback with this approach is that I can't know how long to delay the operations, and they are surely device and list contents specific. I've had to increase the delays to hide the issues and it's impossible to get it right. My current hack is:
Xamarin.Forms 5-pre3, iOS (didn't test on Android).
The text was updated successfully, but these errors were encountered: