Check view is non-null before scrolling, fix crash in NotificationsFragment (#3594)

The posted message runs at the end of the message queue, by which time the view may no longer exist.
This commit is contained in:
Konrad Pozniak 2023-04-29 16:39:49 +02:00 committed by GitHub
parent 2f512705e8
commit a5578cf765
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -211,7 +211,9 @@ class NotificationsFragment :
override fun onItemRangeInserted(positionStart: Int, itemCount: Int) { override fun onItemRangeInserted(positionStart: Int, itemCount: Int) {
if (positionStart == 0 && adapter.itemCount != itemCount) { if (positionStart == 0 && adapter.itemCount != itemCount) {
binding.recyclerView.post { binding.recyclerView.post {
binding.recyclerView.scrollBy(0, Utils.dpToPx(requireContext(), -30)) if (getView() != null) {
binding.recyclerView.scrollBy(0, Utils.dpToPx(requireContext(), -30))
}
} }
} }
} }