Firestore UI Pagination for chatting
Contents
The default behaviour of the recyclerview in Android is adding the new item to the top of its list when this is not the best practice for a chatting UI that needs to add a new item to the bottom of the list then scroll to the last item (the newly added), so in this short tutorial we will show how we can make this possible in two simple steps.
Force the recyclerview to add the new items to the bottom
We can do this by adding a custom layout manager to the recyclerview as following:
|
|
Make the recycler view scroll to the bottom when the new item is added
We are using the Firestore recycler adapter to organize our chat, so we can use the following code to make the recyclerview scroll to the bottom when the activity start (onCreate() or onStart()) or if we wanted to have a refresh, for example in the case that you provided your UI with Swipe refresh to load more messages:
|
|
With these both steps, we can control the arranging and the scrolling of our recyclerview in the case of the Firestore recycler adapter.
Author Jagar
LastMod 2019-11-15