From a5578cf765af0a1c657b6c8e95e22fac91279dd7 Mon Sep 17 00:00:00 2001 From: Konrad Pozniak Date: Sat, 29 Apr 2023 16:39:49 +0200 Subject: [PATCH] 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. --- .../tusky/components/notifications/NotificationsFragment.kt | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/app/src/main/java/com/keylesspalace/tusky/components/notifications/NotificationsFragment.kt b/app/src/main/java/com/keylesspalace/tusky/components/notifications/NotificationsFragment.kt index 8bc17e27..b2eb1dac 100644 --- a/app/src/main/java/com/keylesspalace/tusky/components/notifications/NotificationsFragment.kt +++ b/app/src/main/java/com/keylesspalace/tusky/components/notifications/NotificationsFragment.kt @@ -211,7 +211,9 @@ class NotificationsFragment : override fun onItemRangeInserted(positionStart: Int, itemCount: Int) { if (positionStart == 0 && adapter.itemCount != itemCount) { binding.recyclerView.post { - binding.recyclerView.scrollBy(0, Utils.dpToPx(requireContext(), -30)) + if (getView() != null) { + binding.recyclerView.scrollBy(0, Utils.dpToPx(requireContext(), -30)) + } } } }