arimorty / floatingsearchview

A search view that implements a floating search bar also known as persistent search
https://github.com/arimorty/floatingsearchview/blob/master/README.md
Apache License 2.0
3.54k stars 667 forks source link

Fix reversed suggestions #262

Open eduardbosch opened 7 years ago

eduardbosch commented 7 years ago

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);

Before the fix

incorrect_swap

After the fix

correct_swap