Skip to content

Commit

Permalink
Merge pull request #5828 from Bnyro/master
Browse files Browse the repository at this point in the history
feat: dismiss keyboard at back press on search page
  • Loading branch information
Bnyro committed Mar 28, 2024
2 parents c2aea42 + 868bcde commit 9b74af9
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
package com.github.libretube.extensions

import android.view.View
import android.view.ViewGroup
import androidx.core.view.children

fun View.anyChildFocused(): Boolean {
if (isFocused) return true

if (this is ViewGroup) {
return children.any { it.anyChildFocused() }
}

return false
}
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ import com.github.libretube.compat.PictureInPictureCompat
import com.github.libretube.constants.IntentData
import com.github.libretube.constants.PreferenceKeys
import com.github.libretube.databinding.ActivityMainBinding
import com.github.libretube.extensions.anyChildFocused
import com.github.libretube.extensions.toID
import com.github.libretube.helpers.NavBarHelper
import com.github.libretube.helpers.NavigationHelper
Expand Down Expand Up @@ -170,6 +171,11 @@ class MainActivity : BaseActivity() {
onUserLeaveHint()
}

R.id.searchFragment -> {
if (searchView.anyChildFocused()) searchView.clearFocus()
else navController.popBackStack()
}

R.id.searchResultFragment -> {
navController.popBackStack(R.id.searchFragment, true) ||
navController.popBackStack()
Expand Down

0 comments on commit 9b74af9

Please sign in to comment.