From 76a250925f6375eb9cd6eaf71e689f42bc3f29eb Mon Sep 17 00:00:00 2001 From: Michael Mc Donnell Date: Sat, 14 Dec 2024 21:43:39 -0500 Subject: [PATCH] Fix scroll down performance Scrolling down was slow (see issue #65) because the keyboard was being hidden every time there was a scroll down event. Hiding the keyboard is an expensive operation (found through profiling). They keyboard only needs to be hidden if the search bar is being used (in focus). --- .../kotlin/org/fossify/home/fragments/AllAppsFragment.kt | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/app/src/main/kotlin/org/fossify/home/fragments/AllAppsFragment.kt b/app/src/main/kotlin/org/fossify/home/fragments/AllAppsFragment.kt index 2f167db4..c5c7b1f2 100644 --- a/app/src/main/kotlin/org/fossify/home/fragments/AllAppsFragment.kt +++ b/app/src/main/kotlin/org/fossify/home/fragments/AllAppsFragment.kt @@ -113,7 +113,10 @@ class AllAppsFragment( shouldIntercept = distance > 0 && binding.allAppsGrid.computeVerticalScrollOffset() == 0 if (shouldIntercept) { - activity?.hideKeyboard() + // Hiding is expensive, only do it if focused + if (binding.searchBar.hasFocus()) { + activity?.hideKeyboard() + } activity?.startHandlingTouches(touchDownY) touchDownY = -1 } @@ -221,7 +224,8 @@ class AllAppsFragment( binding.allAppsFastscroller.setPadding(leftListPadding, 0, rightListPadding, 0) binding.allAppsGrid.addOnScrollListener(object : OnScrollListener() { override fun onScrolled(recyclerView: RecyclerView, dx: Int, dy: Int) { - if (dy > 0 && binding.allAppsGrid.computeVerticalScrollOffset() > 0) { + // Hiding is expensive, only do it if focused + if (binding.searchBar.hasFocus() && dy > 0 && binding.allAppsGrid.computeVerticalScrollOffset() > 0) { activity?.hideKeyboard() } }