floatingsearchview
floatingsearchview copied to clipboard
Fix reversed suggestions
Hi again 🎉
I've fixed that if swapSuggestions
is called twice in a row, then the suggestions are displayed incorrectly.
The problem
OnGlobalLayoutListener
is called twice for single suggestion swap if we call swapSuggestion
in the same frame. The problem is that the second time we call swapSuggestion
, OnGlobalLayoutListener
has still not being called, so it ends up calling it twice (or many times).
The solution
Instead of removing the listener when it's processed, we remove it every time we try to swap suggestions.
Test
To test this problem, I've called the swapSuggestions
twice in a row:
mSearchView.swapSuggestions(someSuggestions);
mSearchView.swapSuggestions(someOtherSuggestions);