tom5079 / FloatingSearchView

Complete Kotlin port of arimorty/FloatingSearchView
Apache License 2.0
18 stars 5 forks source link

I have to click twice to close the search bar #4

Closed EmmanuelMess closed 2 years ago

EmmanuelMess commented 2 years ago
<?xml version="1.0" encoding="utf-8"?>
<xyz.quaver.floatingsearchview.FloatingSearchView
    xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    android:id="@+id/floating_search_view"
    android:layout_margin="@dimen/search_view_margin"
    android:layout_width="match_parent"
    android:layout_height="?attr/actionBarSize"
    android:gravity="center_vertical"
    android:visibility="gone"
    app:dimBackground="false"
    app:searchHint="@string/search_hint"
    app:leftActionMode="showHome"
    app:close_search_on_keyboard_dismiss="true"/>

"close_search_on_keyboard_dismiss" isn't working.

To show the keyboard I use searchView.setSearchFocused(true) and to close it I tap on the "back" icon, but I have to tap twice.

tom5079 commented 2 years ago

Also works just fine on the sample. Can you check again if it is a bug of this library?

EmmanuelMess commented 2 years ago

Sorry, not the back button, the up button. Got them confused.

EmmanuelMess commented 2 years ago

Also doesn't work with back button on Android 11 with gestures enabled.

tom5079 commented 2 years ago

I think somewhere in your code you're refocusing the searchview. You said you're programmatically focusing it, so check if it is being called after you click the up button. Can you share the code around setSearchFocused?

EmmanuelMess commented 2 years ago
        mainActivity.showSmokeScreen()
        animator.interpolator = AccelerateDecelerateInterpolator()
        animator.duration = 600
        searchView.visibility = View.VISIBLE
        animator.start()
        animator.addListener(
                object : AnimatorListenerAdapter() {
                    override fun onAnimationEnd(animation: Animator) {
                        searchView.setSearchFocused(true)
                        isEnabled = true
                    }
                })
tom5079 commented 2 years ago

yea, you can print something in onAnimationEnd to see if it is being called

tom5079 commented 2 years ago

Or better, just remove the setSearchFocused call and try to see it fixes anything

EmmanuelMess commented 2 years ago

yea, you can print something in onAnimationEnd to see if it is being called

That code sets the view as focused, AFAIK the keyboard doesnt show otherwise. I have no code hiding the keyboard explicitly.

EmmanuelMess commented 2 years ago

Just tested, without the focus set the keyboard will not open.

tom5079 commented 2 years ago

close_search_on_keyboard_dismiss is working as intended. What it does is it clears the focus when the keyboard is closed, nothing more. You need to add the code to close the view. You can use FloatingSearchView.onFocusChangeListener to listen to focus events.