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).
This commit is contained in:
Michael Mc Donnell
2024-12-14 21:43:39 -05:00
parent 3b8a6de77b
commit 76a250925f

View File

@@ -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()
}
}