Skip to content
This repository was archived by the owner on Dec 18, 2022. It is now read-only.

Commit ea1d440

Browse files
committed
move method for closing the keyboard to companion object
1 parent 8802ecd commit ea1d440

File tree

1 file changed

+9
-6
lines changed

1 file changed

+9
-6
lines changed

sampleapp/src/main/java/io/matthewnelson/sampleapp/ui/fragments/settings/CloseKeyBoardNavListener.kt

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,14 @@ import androidx.navigation.NavController
88
import androidx.navigation.NavDestination
99

1010
class CloseKeyBoardNavListener(private val view: View): NavController.OnDestinationChangedListener {
11+
12+
companion object {
13+
fun closeKeyboard(view: View) {
14+
val imm = view.context.getSystemService(Context.INPUT_METHOD_SERVICE) as InputMethodManager?
15+
imm?.hideSoftInputFromWindow(view.windowToken, 0)
16+
}
17+
}
18+
1119
private var startLock: Any? = null
1220

1321
override fun onDestinationChanged(
@@ -20,12 +28,7 @@ class CloseKeyBoardNavListener(private val view: View): NavController.OnDestinat
2028
return
2129
}
2230

23-
closeKeyboard()
31+
closeKeyboard(view)
2432
controller.removeOnDestinationChangedListener(this)
2533
}
26-
27-
private fun closeKeyboard() {
28-
val imm = view.context.getSystemService(Context.INPUT_METHOD_SERVICE) as InputMethodManager?
29-
imm?.hideSoftInputFromWindow(view.windowToken, 0)
30-
}
3134
}

0 commit comments

Comments
 (0)